• 1279 验证角谷猜想


    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
     1 #include <iostream>
     2 #include <algorithm>
     3 #include <stdio.h>
     4 #include <math.h>
     5 #include <string.h>
     6 #include <time.h>
     7 using namespace std;
     8 
     9 int main()
    10 {
    11     int a[10005];
    12     int n,m,i,j,k;
    13     while(cin>>m)
    14     {
    15         while(m--)
    16         {
    17             cin>>n;
    18             k=0;
    19             while(n!=1)
    20             {
    21                 if(n%2==0)
    22                 n=n/2;
    23                 else
    24                 {
    25                     a[k]=n;
    26                     k++;
    27                     n=n*3+1;
    28                 }
    29             }
    30             if(k>0)
    31             {
    32                 for(i=0;i<k-1;i++)
    33                 {
    34                     cout<<a[i]<<" ";
    35                 }
    36                 cout<<a[k-1]<<endl;
    37             }
    38             else
    39             cout<<"No number can be output !"<<endl;
    40         }
    41     }
    42     return 0;
    43 }
    View Code
  • 相关阅读:
    Hadoop是什么
    Hadoop的安装模式
    hadoop和云计算的关系
    no server suitable for synchronization found的解决办法
    hadoop的产生背景、发展历程
    Hadoop生态系统
    学习路线
    日历+时钟
    新世界(未完善)
    简单的点击切换图
  • 原文地址:https://www.cnblogs.com/wang-ya-wei/p/5251670.html
Copyright © 2020-2023  润新知