HDU 1210 Eddy's shuffling Problem

Source: Internet
Author: User
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;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.