XXX LawTime
limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 2759 Accepted Submission (s): 2035
Problem description for a number n, if it is even, cut off n half, if it is odd, turn N to 3*n+ 1 and cut it down by half until the number becomes 1.
Please calculate how many steps it takes to change N to 1, which is a concrete example.
The input test contains multiple use cases, each containing an integer n, which indicates the end of the input when n is 0. (1<=n<=10000)
Output for each set of test cases, print a number that represents the number of steps that need to elapse, one row for each set of outputs.
Sample Input
310
Sample Output
50
SOURCE Zhejiang University Computer Postgraduate exam on the machine-2009
#include <stdio.h>int main () {int n,t;while (scanf ("%d", &n) &&n) {T=0;while (n!=1) { if (n&1) n= (n*3+1)/2;else
XXX law (Hangzhou electric oj3782)