📄 371 akermann.cpp
字号:
#include<iostream>
using namespace std;
int main()
{
long long i,j,max,t,l,change,req,start,end;
while(cin>>i>>j)
{
start=i;
end=j;
max=0;
t=1;
if(i==0 && j==0)
break;
if(i>j)
{
change=i;
i=j;
j=change;
}
while(j>=i)
{
l=i;
t=1;
do
{
if(i%2==0)
i=i/2;
else
i=3*i+1;
t++;
}while(i!=1);
if(t>max)
{
req=l;
max=t;
}
l++;
i=l;
}
if(start<=end)
cout<<"Between "<<start<<" and "<<end<<", "<<req<<" generates the longest sequence of "<<(max-1)<<" values."<<endl;
if(start>end)
cout<<"Between "<<end<<" and "<<start<<", "<<req<<" generates the longest sequence of "<<(max-1)<<" values."<<endl;
}
system("pause") ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -