problem 100---The 3n + 1 problem(UVA)----2005/4/15
邢臻
2023-12-01
Dear Gilbert_Lee: You are trying to solve "The 3n + 1 problem" (problem 100). I have received and stored your C program. It will be compiled and run as soon as possible; please be patient waiting for the results... -- The Online Judge --------------- The program I'll compile begins here: --------------- /* Author: Gilbert_Lee Email: Gilbert_Lee@163.com Date: 2006-4-8 Address:Sichuan University @ Zhulin cun Website:http://online-judge.uva.es/p/v1/100.html Problem_100 */ #include
void main() { int a, b, result, i, temp, k, m, n; while(scanf("%d%d", &a, &b) == 2) { result = 0; if(a > b) { m = b; n = a; } else { m = a; n = b; } for(i = m; i <= n; i++) { temp = 0; k = i; while(1) { temp++; if(k == 1) { break; } else if(k%2 == 1) { k = k*3 + 1; } else if(k%2 == 0) { k = k/2; } } if(result < temp) { result = temp; } } printf("%d %d %d/n", a, b, result); } }