Skip to content

Instantly share code, notes, and snippets.

@Getmrahul
Last active July 30, 2016 05:54
Show Gist options
  • Save Getmrahul/fc5998b6a5b8b204bf7a57a22e27b642 to your computer and use it in GitHub Desktop.
Save Getmrahul/fc5998b6a5b8b204bf7a57a22e27b642 to your computer and use it in GitHub Desktop.
Find sum of numbers which has only 2 1's in it's binary form
# give input in single line with spaces
nos = map(int, (raw_input()).split(' '))
totalSum = 0
for n in nos:
count = 0
tmpN = n
while n:
n &= (n-1)
count += 1
if count > 2:
break
if count == 2:
totalSum += tmpN
print totalSum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment