Binary number system


Plus
Pin


Problem description Progress
ID 21762. Number of ones in binary SS
Темы: Binary number system   

Given a natural decimal number N. Find the number of ones in the binary representation of the given number. Output the answer in decimal notation.

Input
The input is a single natural number N (\(N<=255\)).

Imprint
Display the answer to the problem.
 

 

Example
# Input Output
1 100 3

 

ID 32965. Next number
Темы: Binary number system   

Given a natural number N. It is necessary to determine the number following it, in the binary decomposition of which there are as many units as in the binary decomposition of the number N.
 
Input
The input contains a single natural number N (\(N <= 2^{30}\)).
 
Output
Display the answer to the problem.
 

 

Examples
# Input Output
1 1 2
2 2 4
3 3 5

ID 38431. funny game
Темы: while loop    Binary number system   

The legendary math teacher Yuri Petrovich came up with a fun game with numbers. Namely, taking an arbitrary integer, he translates it into a binary number system, getting some sequence of zeros and ones, starting with one. (For example, decimal 1910 = 1·24+0·23+0·22+1·21 +1·20 in binary system will be written as 100112.) Then the teacher starts shifting the digits of the resulting binary number around the cycle (so that the last digit becomes the first , and all the rest are shifted one position to the right), writing out the resulting sequences of zeros and ones in the column — he noticed that regardless of the choice of the initial number, the resulting sequences begin to repeat from a certain moment. And, finally, Yuri Petrovich finds the maximum of the numbers written out and translates it back into the decimal number system, considering this number the result of the manipulations done. So, for the number 19, the list of sequences would be:
10011
11001
11100
01110
00111
10011

and the result of the game will therefore be the number 1·24+1·23+1·22+0·2 1+0·20 = 28.

Since the invented game with numbers takes more and more of the teacher's imagination, thereby distracting him from working with very gifted schoolchildren, you are asked to write a program that would help Yuri Petrovich get the result of the game without tedious manual calculations.
Input format
The input file contains one integer N (0 ≤ N ≤ 32767).
Output format
Your program should print to the output file a single integer equal to the result of the game.

Examples
# Input Output
1 19 28