uva 100
坑点:
1.i不一定比j小。
2.可能出现溢出,用long long int
Status | Accepted |
---|---|
Time | 10ms |
Length | 636 |
Lang | C++ 5.3.0 |
#include "cstdio"
#include "bits/stdc++.h"
#define ll long long
using namespace std;
const int maxn=1e6+2;
ll dp[maxn];
ll check(ll a)
{
if(a<maxn &&dp[a])return dp[a];
ll get;
if(a%2)get=check(a*3+1)+1;
else get=check(a/2)+1;
if(a<maxn)return dp[a]=get;
else return get;
}
int main(void)
{
int a,b;
dp[1]=1;
while (scanf("%lld %lld",&a,&b)!=EOF)
{
ll ans=0;
ll aa,bb;
aa=min(a,b);
bb=max(a,b);
for(ll i=aa;i<=bb;++i)
{
ans=max(ans,check(i));
}
printf("%lld %lld %lld\n",a,b,ans);
}
return 0;
}