现在的位置: 首页 > 综合 > 正文

HDU ACM 1279 验证角谷猜想

2019年03月09日 ⁄ 综合 ⁄ 共 245字 ⁄ 字号 评论关闭

水题

#include<iostream>   
using namespace std;

int main()  
{
	int n,T;
	bool flag;

	cin>>T;
	while(T--)
	{
		cin>>n;
		flag=false;
		while(n>1)
		{
			if(n%2==0) n/=2;
			else
			{
				if(!flag)
				{
					cout<<n;
					flag=true;
				}
				else cout<<" "<<n;
				n=n*3+1;
			}
		}
		if(!flag) cout<<"No number can be output !";
		cout<<endl;
	}
    return 0;  
}

抱歉!评论已关闭.