Computer Science, asked by monudinu2531, 1 month ago

write a program to determine whether the number N is equal to the sum of its proper positive divisor(excluding the number itself)​

Attachments:

Answers

Answered by anindyaadhikari13
52

\textsf{\large{\underline{Solution}:}}

The given problem is solved using language - Python.

def check(x):

   sum=0

   for i in range(1,x//2+1):

       if x%i==0:

           sum+=i

   if sum==x:

       return 'YES'

   return 'NO'

test_cases=int(input())

list=list()

for i in range(test_cases):

   list.append(int(input()))

print('\n-------------\n')

for i in list:

   print(check(i))

\textsf{\large{\underline{Explanation}:}}

  • The function check(x) checks whether a number is equal to the sum of its proper divisors. It returns 'YES' if true and 'NO' if false.
  • Now, the number of test cases is taken as input. The numbers are then stored inside list.
  • The function check(x) is called to display the required output.

See the attachment for output.

Attachments:
Answered by bansalritu702
5

Explanation:

def check(x):

sum=0

for i in range(1,x//2+1):

if x%i==0:

sum+=i

if sum==x:

return 'YES'

return 'NO'

test_cases=int(input())

list=list()

for i in range(test_cases):

list.append(int(input()))

print('\n-------------\n')

for i in list:

print(check(i))

Similar questions