#40700: c039


411490252 (411490252tkuee)

學校 : 淡江大學
編號 : 202581
來源 : [122.100.75.83]
最後登入時間 :
2024-06-14 03:07:52
c039. 00100 - The 3n + 1 problem -- UVa100 | From: [122.100.75.83] | 發表日期 : 2024-06-06 20:40

// P01 3N+1問題
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int i, j;
while(cin >>i >>j){
int m = min(i, j);int M = max(i,j);int cycle = 0;
for (int k = m; k <= M; k++){
int n= k;int t =0;while (1){
t++;
if (n ==1) break;
if(n%2) n=3*n+1;
else n=n/2;
}
cycle = max(cycle, t);
}
cout <<i<<" "<< j <<" "<< cycle << endl;
}
return 0; 
}

 
ZeroJudge Forum