验证角谷猜想
1 #include<iostream> 2 using namespace std; 3 int main() 4 { 5 int n; 6 while(cin>>n) 7 { 8 while(n--) 9 { 10 int m,flags=0; 11 cin>>m; 12 while(m!=1) 13 { 14 if(m%2) 15 { 16 if(!flags) 17 cout<<m; 18 else 19 cout<<" "<<m;; 20 m=3*m+1; 21 flags++; 22 23 } 24 else 25 { 26 m/=2; 27 } 28 } 29 if(!flags) 30 cout<<"No number can be output !"; 31 cout<<endl; 32 } 33 } 34 }