The code below isn\'t working right for some inputs.
a, i = set(), 1 while i <= 10000: a.add(i) i <<=
Use *2 instead of bit shifts. Multiplication or addition are much more readable.