UVA 371 - Ackermann Functions UVA • Sep 1, 2020 Problem PDFSolution:#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define ll long long #define sc scanf #define pf printf #define pi 2*acos(0.0) using namespace std; int main() { long long a,b,c,Max,Gn,p,t,i; while(scanf("%lld%lld",&a,&b)==2) { Max=0; if(a==0||b==0) break; if(a>b) swap(a,b); for(i=b;i>=a;i--) { p=i; c=1; if(p%2==0) { p/=2; } else { p=3*p+1; } while(p!=1) { if(p%2==0) { p/=2; c++; } else { p=3*p+1; c++; } } if(c>=Max) { Max=c; Gn=i; } } printf("Between %lld and %lld, %lld generates the longest sequence of %lld values.\n",a,b,Gn,Max); } return 0; } https://github.com/Shipu/OnlineJudgeProblemSolutionWithCPlusPlus/tree/master/uva/371/371.cpp Tags UVA Competitive Programming Shipu Ahamed Recommended for you UVA UVA 913 - Joana and the Odd Numbers 4 years ago • 1 min read UVA UVA 871 - Counting Cells in a Blob 4 years ago • 3 min read UVA UVA 866 - Intersecting Line Segments 4 years ago • 3 min read