Problem Name : The 3n + 1 problem
Problem Link : See Problem : Uva – 100
Sollution :
#include<bits/stdc++.h> #define pb push_back #define read freopen("input.txt","r",stdin) #define write freopen("output.txt","w",stdout) #define rev(s) std::reverse(s.begin(), s.end()); #define up std::transform(s.begin(), s.end(), s.begin(), ::toupper); ///string sb=s.substr(1,3); #define low std::transform(s.begin(), s.end(), s.begin(), ::tolower); #define n2s(n) stringstream ss; ss<<n; string s=ss.str(); #define CC(x) cout<<(x)<<endl #define srt sort(a,a+n); #define rep(n) for(int i=0;i<n;i++) typedef long long LL; using namespace std; LL f(LL n) { LL a=1; while(n!=1) { if(n%2==0){n/=2; a++;} else{n=(3*n)+1; n/=2; a+=2;} } return a; } int main() { LL A,L,ans=0,a,l,an; while(cin>>A>>L) { a=A,l=L,ans=0; if(A>L){swap(A,L);} for(int i=A;i<=L;i++) { an=f(i); ans=max(an,ans); } cout<<a<<" "<<l<<" "<<ans<<endl; } return 0; }