Karaz (Callatz) conjecture:
For any natural number n, if it is even, cut it in half, and if it is odd, cut it off by half (3n+1). This has been repeatedly cut down, and finally must be in a certain step to get n=1. Karaz at the 1950 World Mathematicians conference published this conjecture, the legend of Yale University teachers and students to mobilize, desperately want to prove this seemingly silly very naïve proposition, the result of students do not want to study, the only card (3n+1), so that some people say this is a conspiracy, Karaz is deliberately delaying the progress of teaching and research in the American mathematical world ...
Our topic today is not to prove Karaz conjecture, but to give no more than 1000 positive integers n, simply to count, how many steps (a few cuts) are needed to get n=1?
Input Format: Each test input contains 1 test cases, which gives the value of the natural number N.
output Format: Outputs the number of steps required to calculate from N to 1.
Input Sample: 3
Output Sample: 5
Code
1#include <stdio.h>2 intMain ()3 {4 intn=0;//Receive pre-judged N;5 intI=0;//The number of steps to save the calculation;6scanf"%d",&n);7 while(n!=1)//If not get 1, then always cut;8 {9 if(n%2==0)Ten { OneN/=2; A } - Else - { theN= (3*n+1)/2; - } -i++; - } +printf"%d", i); - return 0; +}
Pat B true title 1001. (3n+1) conjecture (15) (Problem solving)