题解 | #完全数计算#
完全数计算
http://www.nowcoder.com/practice/7299c12e6abb437c87ad3e712383ff84
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
int input = sc.nextInt();
int count=0;
for(int i=1;i<=input;i++){
int sum=0;
int p = i/2+1;
for(int j=1;j<=p;j++){
if(i%j==0){
sum = sum + j;
}
count++;
}
}
System.out.println(count);
}
}
}
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
int input = sc.nextInt();
int count=0;
for(int i=1;i<=input;i++){
int sum=0;
int p = i/2+1;
for(int j=1;j<=p;j++){
if(i%j==0){
sum = sum + j;
}
}
// 循环遍历这个数的 公约数,求和和自己比较,因为1只有自身去掉,然后count求和
if(i != 1 && sum == i){count++;
}
}
System.out.println(count);
}
}
}