Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- import heapq
- def tao():
- threshold = 1000000
- k = 1 # power of 2
- mods = set([0, 1]) # modulo classes
- while True:
- print (k, len(mods))
- newmods = set()
- for i in mods:
- # keep track of the number 2^m 3^n + j as (2^m3^n + j, m, n, j),
- # and a third component that tells us how many times we may multiply by 3
- allowed = int(math.ceil(math.log(2) / math.log(3))) * k
- numbers = set([(2**k, k, 0, i)])
- frontier = list(numbers)
- success = False
- while True:
- if len(frontier) == 0:
- break
- val, m, n, j = heapq.heappop(frontier)
- if 2**m * 3**n < 2**k:
- success = True
- if m > 0 and j % 2 == 0:
- elem = (val//2, m - 1, n, j//2)
- if elem not in numbers:
- numbers.add(elem)
- heapq.heappush(frontier, elem)
- if 3**(n + 1) < 2**k:
- elem = (3*val + 1, m, n + 1, 3*j + 1)
- if elem not in numbers:
- numbers.add(elem)
- heapq.heappush(frontier, elem)
- if not success:
- newmods.add(i)
- mods = newmods
- if len(mods) == 0:
- print("Ya.")
- return
- newmods = set()
- for m in mods:
- newmods.add(m)
- newmods.add(m + 2**k)
- mods = newmods
- k += 1
- tao()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement