Algorithm notes -Day_01 (1001 killed attractiveness of the (3n + 1) guess

Kharazi (Callatz) guess:

For any positive integer n, if it is even, then it halved; if it is odd, then the ( . 3 n- + . 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 permit ( 3 the n- + 1 ), so some people say 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 <stdio.h> 

int main () { 
	The freopen ( "in.txt", "R & lt", stdin); 
	int A, ANS = 0; 
	Scanf ( "% D", & A); 
	
	the while (A =. 1! ) {// little attention here, equal to a direct return 0 
		IF (A% 2 == 0) { 
			A = A / 2; 
			ANS + = 1; 
		} the else { 
			A = (A * + 1. 3) / 2; 
			ANS =. 1 +;	 
		} 
	}	 
	the printf ( "% D", ANS); 
	return 0;	 
}

  




Guess you like

Origin www.cnblogs.com/luyuan-chen/p/11410165.html