判断是不是完全数

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);
        }
    }
}
posted on 2023-05-01 17:33  逆袭怪  阅读(12)  评论(0编辑  收藏  举报