Count the 1s in the binary representation

 Coding Problem Keys 

 Count the 1s in the binary representation 

 Problem Statement 

A positive integer N is passed as the input. The program must print the number of 1s in the binary representation of N.

 Boundary Condition(S) 

1 <= N <= 9000000000000000000

 Input Format 

The first line will contain the value of N.

 Output Format 

The first line will contain the count of 1s in their binary representation.

 Example Input/Output 1 

 Input 

22

 Output 

3

 Note: Max Execution Time Limit: 5000 millisecs 

 Solution 

 Programming Language: Python 3 Language 

print(bin(int(input()))[2:].count('1'))

# Published By PKJCODERS

 (Note: Incase If the code doesn't Pass the output kindly comment us with your feedback to help us improvise.) 

Comments

Anonymous said…
this program is not compiling....

File "Hello.py", line 1 in
print(bin.......)))

TypeError: 'int' object is not subscriptable
PKJ said…
Thank You for your assist.
-PKJCODERS Admin

Popular Posts

Top Scoring Batsman - TEST ODI 20-20

Largest Possible Number With Digits

Highly Profitable Months

Minimum Sum of Non-Negative Elements

Count Embedded Integers in String

String - Vowels Position Sum

Desktop Products