halaluddin

problem-31

May 10th, 2019
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. def Prime(p):
  2. return 2 in [p, 2**p%p]
  3.  
  4. def Mersenne_prime(p):
  5. if Prime(p):
  6. p = ((2**p) - 1)
  7. if Prime(p):
  8. return True
  9. return False
  10. def Euclid_Theory(p):
  11. if Mersenne_prime(p):
  12. perfect_num = ((2**(p-1)) * ((2**p) - 1))
  13. return perfect_num
  14. return 0 #if Mersenne is False then return 0 else return perfect_num
  15.  
  16. def Solve(area):
  17. odd = 2
  18. perfect_num = Euclid_Theory(odd)
  19. odd = 3
  20. while True:
  21. if perfect_num > area:
  22. break
  23. else:
  24. if perfect_num != 0:
  25. print(perfect_num)
  26. perfect_num = Euclid_Theory(odd)
  27. odd += 2
  28.  
  29. if __name__ == "__main__":
  30. t = int(input())
  31. for i in range(1, t+1):
  32. area = int(input())
  33. if area >= 6:
  34. Solve(area)
  35. if i != t:
  36. print()
Add Comment
Please, Sign In to add comment