Python3 代码
import math
n = int(input())
for i in range (n):
x = int(input())
if x == 1:
print (x, "is not perfect")
continue
x2 = math.floor(math.sqrt(x))
sum = 1
for i in range (2, x2 + 1):
if x % i == 0:
sum += i
y = x / i
if i != y:
sum += y
if sum == x:
print (x, "is perfect")
else:
print (x, "is not perfect")