您的位置:首页 > 其它

UVa100 The 3n + 1 problem

2016-04-21 18:55 232 查看
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=36注意 i j的大小不定,得调整。国外的都这么坑吗。
#include<iostream>
#define ll long long
using namespace std;
int s(ll n)
{
int c;
for(c=1;n!=1;c++)
{
if(n&1)n=n*3+1;
else n/=2;
}
return c;
}

int main()
{
int a,b,t;
while(cin>>a>>b)
{
cout<<a<<" "<<b<<" ";
if(a>b){t=a;a=b;b=t;}
int Max=-1;
for(int i=a;i<=b;i++)
{
int k=s(i);
if(k>Max) Max=k;
}
cout<<Max<<endl;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: