cycle shifts

write the decimal integer n in binary notation and create all its left cycle shifts where first digit of the number goes to the end.

For example, if n = 11, than it will be 1011 in binary notation, cycle shifts are 0111, 1110, 1101, 1011. So the maximal value m among all received numbers equals to 11102 = 1410.

For the number n find the maximal value of m.

Input

One number n (1 ≤ n ≤ 2 ·109).

Output

One number m.
Last edited on
#include <iostream>

using namespace std;


int main()
{
int X,D,M,m;
cin>>X;
M=m=D=X;
while(D & D-1)D&=D-1;
m=(X>>1)| D*(X & 1);
while(m!=X){M=max(m,M);m=(m>>1)| D*(m & 1);}
cout<<M;

return 0;
}
Topic archived. No new replies allowed.