Last active
July 30, 2016 05:54
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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