HDU 1210 Eddy's shuffling problem descriptioneddy is an acmer. He not only likes to do ACM, but also has some research on cards. He found that when he is bored, if he has 2n cards, numbers 1, 2, 3 .. n, N + 1 ,.. 2n. This is also the initial order of cards. By shuffling a card, you can change the card sequence to N +, N + 4, 4 .. 2n, N. It can be proved that for any natural number N, the initial order can be re-obtained for the first time after M shuffling. For a natural number n Less than 100000, calculate the m value.
Input each line has an integer n. The output corresponds to M sample input201sample output202.
// This topic mainly tracks one of the elements. If it is moved to the origin, it indicates that it has been restored.
# Include <iostream>
Using namespace STD;
Int main ()
{
Int N, P, num;
While (CIN> N)
{
P = 1;
Num = 0;
While (1)
{
If (P <= N)
P = 2 * P; // if it is the first half, multiply it by the second to be its next position.
Else
P = 2 * (p-n)-1; // if it is the last half
Num ++;
If (P = 1) // if you return to the origin
Break;
}
Cout <num <Endl;
}
Return 0;
}