判断是不是完全数
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
while (n -- > 0)
{
int x = sc.nextInt(), sum = -x;
for (int i = 1; i * i <= x; i ++) {
if (x % i == 0) {
sum += i;
if (i != x / i) sum += x / i;
}
}
if (sum == x) System.out.printf("%d is perfect\n", sum);
else System.out.printf("%d is not perfect\n", x);
}
}
}
本文来自博客园,作者:逆袭怪,转载请注明原文链接:https://www.cnblogs.com/fghjktgbijn/p/17366757.html