Link: http://pat.zju.edu.cn/contests/pat-b-practise/1001
Callatz conjecture:
For any natural number N, if it is an even number, cut it by half; if it is an odd number, cut (3N + 1) by half. In this way, we will continue to cut down and finally get n = 1 in a certain step. Karaz announced this conjecture at the world mathematician conference in 1950. It is said that at that time, the teachers and students of Yale University were mobilized to prove this seemingly silly and naive proposition, and the results made the students unwilling to study, as a result, some people say this is a conspiracy. karaz is deliberately delaying the progress of teaching and scientific research in American mathematics ......
Today's question is not to prove caraz's conjecture, but to give a given positive integer n of no more than 1000, simply count it. How many steps (cut down) Do we need to get n = 1?
Input Format:Each test input contains one test case, that is, the value of natural number n.
Output Format:The number of steps required for the output from N to 1.
Input example:
3
Output example:
5
The Code is as follows:
#include <cstdio>int main(){ int n; while(~scanf("%d",&n)) { int k = 0; while(n > 1) { if(n%2) { n = (3*n+1)/2; } else n/=2; k++; } printf("%d\n",k); } return 0;}
Pat 1001. The (3N + 1) conjecture that the dead are not worth the candle (15)