learningpython/powerOf2.py

18 lines
292 B
Python
Raw Normal View History

#! /usr/bin/env python3
def slowMethod(n):
while (n!=1):
if (n%2!=0):
return False
n = n //2
return True
def fastMethod(n):
return (n&(n-1))==0
for n in range(1,1000000):
if slowMethod(n):
print(n)
if fastMethod(n):
print(n)