File tree Expand file tree Collapse file tree 1 file changed +67
-0
lines changed Expand file tree Collapse file tree 1 file changed +67
-0
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ layout : post
3+ title : 1279.验证角谷猜想
4+ date : 2014-10-05 14:18
5+ categories : 杭电HDU
6+ tags : [杭电HDU]
7+ ---
8+ ## Problem
9+ > ** Problem Description**
10+ 数论中有许多猜想尚未解决,其中有一个被称为“角谷猜想”的问题,该问题在五、六十年代的美国多个著名高校中曾风行一时,这个问题是这样描述的:任何一个大于一的自然数,如果是奇数,则乘以三再加一;如果是偶数,则除以二;得出的结果继续按照前面的规则进行运算,最后必定得到一。现在请你编写一个程序验证他的正确性。
11+ ** Input**
12+ 本题有多个测试数据组,第一行为测试数据组数N,接着是N行的正整数。
13+ ** Output**
14+ 输出验证“角谷猜想”过程中的奇数,最后得到的1不用输出;每个测试题输出一行;每行中只有两个输出之间才能有一个空格;如果没有这样的输出,则输出:No number can be output !。
15+ ** Sample Input**
16+ 4
17+ 5
18+ 9
19+ 16
20+ 11
21+ ** Sample Output**
22+ 5
23+ 9 7 11 17 13 5
24+ No number can be output !
25+ 11 17 13 5
26+
27+ ## Solution
28+ ``` cpp
29+ #include < stdio.h>
30+ int main (void)
31+ {
32+ int count,sign,i,a,t;
33+
34+ while(scanf("%d",&count)!=EOF){
35+ for(i=0;i<count;i++){
36+ sign=1;
37+ scanf("%d",&a);
38+ t=a;
39+ while(1){
40+ if(t%2==0){
41+ t=t/2;
42+ }
43+ if(t==1){
44+ printf("\n");
45+ break;
46+ }
47+ if(t%2!=0&&t!=1){
48+ if(sign==1){
49+ printf("%d",t);
50+ t=t* 3+1;
51+ sign=2;
52+ }
53+ else{
54+ printf(" %d",t);
55+ t=t* 3+1;
56+ }
57+ }
58+ if(sign==1){
59+ printf("No number can be output !");
60+ sign=3;
61+ }
62+ }
63+ }
64+ }
65+ return 0;
66+ }
67+ ```
You can’t perform that action at this time.
0 commit comments