ACM (UVa): 10019


Data type:
Long Integer / Integer

Procedure:
Let, X is a decimal number. Convert it into binary and count the number of 1’s. This process can even be shorter.
If (X MOD 2 = 1) then, Count++
X/=2
Thus we can count only number of 1’s without get the binary conversion.
Now, Let X = 265 is a Hexadecimal Number. Converting Hexadecimal to Binary is very simple. Just do the previous process digit by digit.

Critical Input:
5
9999
9998
0
2568
2477

Critical Output:
8 8
7 7
0 0
3 6
7 8

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s