The 3n+1 problem is a simple, interesting and unsolved mathematical problem. The problem was raised by Collatz in 1937. The Korazim problem (Collatz problem) is also called hailstone problem, 3n+1 problem, Hassealgorithm problem, Kakutani algorithm problem, Thwaites conjecture or Ulam problem. The problem is as follows: (1) Enter a positive integer n, (2) If N=1 ends, (3) if n is odd, n becomes 3n+1, otherwise n becomes N/2; (4) Moves to step (2). The special point of the Korazim problem is that, although it is easy to clarify the problem, it is still not guaranteed that the algorithm for this problem will work for all possible inputs-that is, no one has proven that the process terminates for all positive integers. For example: n=9, there are 9 28 14 7 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1
PublicClassCollatz {/*** Collatz Questions *@paramNumber*/PublicStaticvoid Collatzq (IntNumber) {String result = "";int TMP =NumberWhileTrue){if (tmp = = 1) {result = result + "Over"; SYSTEM.OUT.PRINTLN (result);Break; }Elseif (TMP <= 0{SYSTEM.OUT.PRINTLN ("the number is Error!!!")); break;} else { if (tmp% 2 = = 0) {tmp = TMP/2;} else {tmp = 3 * tmp + 1;} result = result + tmp + "\ T";}}} public static void main (string[] args) {for (int num = 0; num < num++) {Collatz. COLLATZQ (num); } }}
The number is Error!!! Over1 Over10 5 8 4 2 1 Over2 1 Over16 8 4 2 1 Over3 5 8 4 2 1 Over22 11 34 17 52 26 5 8 4 2 1 Over4 2 1 Over28 7 -Ten-5-8 4-2-1
Reference: http://www.xuebuyuan.com/2025609.html
"Practice" Korazim questions