PAT Basic 1001 killed attractiveness of the (3n + 1) guess (15 points)

Kharazi (Callatz) guess:

For any positive integer  n, if it is even, then it halved; if it is odd, the  (3n + 1) cut by half. This has been repeatedly cut, finally got to get a step in  the n- = 1. Kharazi at the 1950 World Congress of Mathematicians announced this conjecture, was the legendary Yale University teachers and students Qidong Yuan, desperately want to prove this seemingly silly naive proposition, students inadvertently result so much noise studies, one only card  (, Some people say that this is a conspiracy, Kharazi was deliberately delaying the progress of American mathematics teaching and research ......

Our topic today is not evidence Minka Raz conjecture, but on any given positive integer not exceeding 1,000  n, simply count the number, how many steps (cut a few) need to get  the n- = 1?

Input formats:

Each test comprises a test input, i.e., it gives a positive integer  value of n.

Output formats:

Outputted from the  calculation of the required number of steps to n 1.

Sample input:

3

Sample output:

5

#include <iostream>
using namespace std;
int main(){
    int n,count=0;
    cin>>n;
    while(n!=1){
        if(n%2==0) n/=2;
        else n=(3*n+1)/2;
        count++;
    }
    cout<<count;
    system("pause");
    return 0;
}

 



Guess you like

Origin www.cnblogs.com/littlepage/p/11267547.html