Verifying the Angle Valley conjecture
Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 6653 Accepted Submission (s): 3417
There are many speculations in problem description number theory that have not yet been resolved, one of which is known as the "Angular Valley conjecture", a problem that was popular in several prestigious universities in cert, the problem is described as: any one greater than the natural number, if it is odd, is multiplied by three plus one, and if an even number is divided by two, the resulting result continues to be computed according to the preceding rule, and one must finally be obtained. Now ask you to write a program to verify his correctness.
Input has multiple test data sets, the first behavior tests the number of data groups N, followed by the N-line positive integers.
The output outputs verify the odd number in the "Angle Valley conjecture" process, and the last 1 do not output; one row per test problem, only two outputs in each row can have a space, if there is no such output, then the output: No number can be output!.
Sample Input
4591611
Sample Output
7 5No number can be output!11 17 13 5
Water, water, water and water tonight ~ ~
#include <iostream>using namespace Std;int main () {int N;while (cin>>n) {int x;for (int m=0;m<n;m++) {cin >>x;int flag=0;int Ls[1000],t=0;while (x!=1) {if ((x&1)) { flag=1; ls[t++]=x;} if (x%2==0) { x/=2;} else { flag=1; x=x*3+1;} } if (!flag) cout<< "No number can be output!" <<endl;else{int v;for (v=0;v<t-1;v++) cout<<ls[v]<< ""; Cout<<ls[v]<<endl;}} return 0;}
Hangzhou Electric HDU 1279 Verifying the Angle Valley conjecture