Guest User

Untitled

a guest
Mar 25th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. from math import sqrt
  2.  
  3. def get_list(num):
  4. result = [1]
  5.  
  6. upper_bound = sqrt(num)
  7. i = 2
  8.  
  9. while i < upper_bound:
  10. if num % i == 0:
  11. c = num // i
  12. if i != c and c != num:
  13. result += [i, c]
  14. else:
  15. result.append(i)
  16.  
  17. i += 1
  18.  
  19. return result
  20.  
  21. class Solution:
  22. def checkPerfectNumber(self, num):
  23. """
  24. :type num: int
  25. :rtype: bool
  26. """
  27. if num <= 1:
  28. return False
  29. return num == sum(get_list(num))
Add Comment
Please, Sign In to add comment