首页 技术 正文
技术 2022年11月19日
0 收藏 403 点赞 4,005 浏览 737 个字

Problem Description

数论中有许多猜想尚未解决,其中有一个被称为“角谷猜想”的问题,该问题在五、六十年代的美国多个著名高校中曾风行一时,这个问题是这样描述的:任何一个大于一的自然数,如果是奇数,则乘以三再加一;如果是偶数,则除以二;得出的结果继续按照前面的规则进行运算,最后必定得到一。现在请你编写一个程序验证他的正确性。

Input

本题有多个测试数据组,第一行为测试数据组数N,接着是N行的正整数。

Output

输出验证“角谷猜想”过程中的奇数,最后得到的1不用输出;每个测试题输出一行;每行中只有两个输出之间才能有一个空格;如果没有这样的输出,则输出:No number can be output !。

Sample Input

4

5

9

16

11

Sample Output

5

9 7 11 17 13 5

No number can be output !

11 17 13 5

代码:

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int a[10000];
int cmp(int x)
{
return x/2;
}
int mcp(int x)
{
return (3*x+1);
}
int main()
{
int n,i,j,k,m;
while(cin>>n)
{
while(n--)
{ i=0;
cin>>m;
while(m!=1)
{
if(m%2==0)
m=cmp(m);
else
{
a[i++]=m;
m=mcp(m);
}
}
if(i==0)
cout<<"No number can be output !"<<endl;
else
{
cout<<a[0];
for(j=1;j<i;j++)
cout<<" "<<a[j];
cout<<endl;
}}
}
return 0;
}

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,088
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,564
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,412
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,185
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,822
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,905