Binary Numbers
Calculate and return number of 1s in binary representation of given number n.
Input format :
Output Format :
Constraints :
1 <= n <= 2^63 - 1
Sample Input :
Sample Output :
Sample Input Explanation :
4 can be represented as 100 in binary, which has only one 1 in binary representation.
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
num=int(input()) | |
print(bin(num).count("1")) |
Comments
Post a Comment
Please give us your valuable feedback