#40700: c039


411490252 (411490252tkuee)

School : 淡江大學
ID : 202581
IP address : [122.100.75.83]
Last Login :
2024-06-14 03:07:52
c039. 00100 - The 3n + 1 problem -- UVa100 | From: [122.100.75.83] | Post Date : 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