hdu 1279 验证角谷猜想

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1279

 1 #include<stdlib.h>
 2 #include<time.h>
 3 #include <cstdio>  
 4 #include <cstring>  
 5 #include <cmath>  
 6 #include <cstdlib>  
 7 #include <ctime>  
 8 #include <iostream>  
 9 #include <algorithm>  
10 #include <vector>  
11 #include <queue>  
12 #include <map>  
13 #include <set>  
14 #include <string>  
15 using namespace std;
16 
17 int main()
18 {
19     int num,n,flag;
20     cin>>num;
21     while(num--)
22     {
23         cin>>n;
24         flag=0;
25         while(n!=1)
26         {
27             if(n%2 == 0)
28             {
29                 n=n/2;    
30             }
31             
32             else
33             {
34                 if(flag != 0)
35                     printf(" ");
36                 printf("%d",n);
37                 n=n*3+1;
38                 flag++;
39             }    
40         
41         } 
42         if(flag == 0)
43             printf("No number can be output !");
44         printf("\n");
45     } 
46     return 0;
47 } 

 

posted @ 2015-10-28 11:21  pter  阅读(119)  评论(0编辑  收藏  举报