#include <cstdio>
#include <cstdlib>
#include <climits>
#include <algorithm>
using namespace std;
long long int table[1024000];
void init(void)
{
for(long long int i=1; i<1000005; i++)
{
long long int x = i;
long long int cnt = 1;
while(x!=1){
x = x % 2 == 0 ? (x / 2) : (3 * x + 1);
if(x<1000005 && table[x]!=0){
cnt += table[x];
break;
}
cnt++;
}
table[i] = cnt;
}
}
int main()
{
init();
int a,b;
while(~scanf("%d %d",&a,&b))
{
int m = INT_MIN;
int i,temp;
printf("%d %d ", a, b);
if(a > b) swap(a, b);
for(i=a; i<=b; i++)
m = max((long long int)m, table[i]);
printf("%d\n",m);
}
return 0;
}
HDU - 1032 The 3n + 1 problem
最新推荐文章于 2021-08-31 00:21:44 发布