This IS Perfect

 Write a program to determine whether a number N is equal to the sum of its proper positive divisors (excluding the number itself).

Input format

  • First line: T (number of test cases)
    For each test case
  • First line: N

Output format

Print YES, if N is equal to the sum of its proper positive divisors else print NO.

Constraints

1 ≤ T ≤ 100
1 ≤ N ≤ 109

Sample Input

3
6
5
28

Sample Output

YES
NO
YES

Explanation

6 = 1 + 2+ 3, so it is perfect.

5 != 1 , so it is not perfect.

28 = 1 + 2 + 4 + 7 + 14, so it is perfect.




Solution:



import math 

t=int(input())

while(t!=0):

    n=int(input())

    s=1

    i=2

    if(n!=1):

        while(i<=(int(math.sqrt(n)))):

            if(n%i==0):

                s=s+i+(n/i)

            i=i+1

        if(s==n):

            print("YES")

        else:

            print("NO")

    else:

        print("NO")

    t=t-1

     

            

        

    

Comments

Popular posts from this blog

Efficient Janitor

Right Arrow Pattern

X Pattern