Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2022
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. import math
  2. import heapq
  3.  
  4. def tao():
  5. threshold = 1000000
  6. k = 1 # power of 2
  7. mods = set([0, 1]) # modulo classes
  8. while True:
  9. print (k, len(mods))
  10. newmods = set()
  11. for i in mods:
  12. # keep track of the number 2^m 3^n + j as (2^m3^n + j, m, n, j),
  13. # and a third component that tells us how many times we may multiply by 3
  14. allowed = int(math.ceil(math.log(2) / math.log(3))) * k
  15. numbers = set([(2**k, k, 0, i)])
  16. frontier = list(numbers)
  17. success = False
  18. while True:
  19. if len(frontier) == 0:
  20. break
  21. val, m, n, j = heapq.heappop(frontier)
  22. if 2**m * 3**n < 2**k:
  23. success = True
  24. if m > 0 and j % 2 == 0:
  25. elem = (val//2, m - 1, n, j//2)
  26. if elem not in numbers:
  27. numbers.add(elem)
  28. heapq.heappush(frontier, elem)
  29. if 3**(n + 1) < 2**k:
  30. elem = (3*val + 1, m, n + 1, 3*j + 1)
  31. if elem not in numbers:
  32. numbers.add(elem)
  33. heapq.heappush(frontier, elem)
  34. if not success:
  35. newmods.add(i)
  36. mods = newmods
  37. if len(mods) == 0:
  38. print("Ya.")
  39. return
  40. newmods = set()
  41. for m in mods:
  42. newmods.add(m)
  43. newmods.add(m + 2**k)
  44. mods = newmods
  45. k += 1
  46.  
  47. tao()
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement