标签:
1 #pragma comment(linker, "/STACK:1024000000,1024000000") 2 #include<iostream> 3 #include<cstdio> 4 #include<cstring> 5 #include<cmath> 6 #include<math.h> 7 #include<algorithm> 8 #include<queue> 9 #include<set> 10 #include<bitset> 11 #include<map> 12 #include<vector> 13 #include<stdlib.h> 14 using namespace std; 15 #define ll long long 16 #define eps 1e-10 17 #define MOD 1000000007 18 #define N 1000000 19 #define inf 1e12 20 int n; 21 vector<int> g; 22 int main() 23 { 24 int t; 25 scanf("%d",&t); 26 while(t--){ 27 g.clear(); 28 scanf("%d",&n); 29 if(n<=1){ 30 printf("No number can be output !\n"); 31 continue; 32 } 33 while(n!=1){ 34 if((n&1) && n!=1) g.push_back(n); 35 36 if(n&1){ 37 n=n*3+1; 38 }else{ 39 n/=2; 40 } 41 42 } 43 44 45 if(g.size()==0){ 46 printf("No number can be output !\n"); 47 continue; 48 } 49 if(g.size()==1){ 50 printf("%d\n",g[0]); 51 continue; 52 } 53 for(int i=0;i<g.size()-1;i++){ 54 printf("%d ",g[i]); 55 } 56 printf("%d\n",g[g.size()-1]); 57 58 } 59 return 0; 60 }
标签:
原文地址:http://www.cnblogs.com/UniqueColor/p/5176662.html