The sequence 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 16, . . . is formed from all positive integers that are either a power of 2 or a sum of two distinct powers of 2. Find the 200th term of this sequence.
Answer: 524544
-----------
from itertools import combinations
big = 20
pow2s = [2**i for i in range(big)]
sum2s = []
for comb in combinations(pow2s, 2):
mysum = sum(comb)
if mysum not in sum2s:
sum2s.append(mysum)
combined = sorted(pow2s + sum2s)
print(combined[199])
|
Posted by Larry
on 2025-03-03 19:29:58 |