您的位置:首页 > 其它

Uva 100 The 3n+1 problem

2016-05-24 10:48 369 查看
#include<iostream>
#include<cstdio>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<cstring>
#include<stack>
using namespace std;

int count(int temp)
{
int total=1;
while(temp!=1)
{
if(temp%2==0)
temp=temp/2;
else
temp=3*temp+1;
total++;
}
return total;
}

int main()
{
int i,j;
while(scanf("%d %d",&i,&j)!=EOF)
{
int start=i;
int end=j;
int t;
if(i>j)
{
t=i;
i=j;
j=t;
}
int maxxx=-1;
while(i<=j)
{
int amount=count(i);
if(amount>maxxx)
maxxx=amount;
i++;
}
printf("%d %d %d\n",start,end,maxxx);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: