CPE 5. The 3n + 1 problem
user_3763047219
c_cpp
2 years ago
711 B
0
Indexable
Never
#include <iostream> #include <string> using namespace std; int main(){ int a,b,n1,n2; int Max; while(cin>>n1>>n2){ if(n1>n2){ a=n2; b=n1; } else{ a=n1; b=n2; } Max=0 ; for(int i=a;i<=b;i++){ int n=i; int time=1; while(n!=1){ if(n%2!=0){ n=3*n+1; } else{ n=n/2; } time++; } if(time>Max){ Max=time; } } cout<<n1<<" "<<n2<<" "<<Max<<endl; } }