AcWing 725. 完全数 - Java
原题链接
中等
作者:
KYCygni
,
2021-03-14 01:28:03
,
所有人可见
,
阅读 390
Java 代码
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner cin = new Scanner(System.in);
int n = cin.nextInt();
for (int i = 0; i < n; i++)
{
int x = cin.nextInt();
if (x == 1)
{
System.out.println (x + " is not perfect");
continue;
}
int sum = 1;
for (int j = 2; j * j <= x; j ++)
{
if (x % j == 0)
{
sum += j;
if ( j != x / j)
sum += x / j;
}
}
if (sum != x)
System.out.println (x + " is not perfect");
else
System.out.println (x + " is perfect");
}
}
}