c++ - UVa_100 3n+1, I got wrong answer -
here code:
#include <iostream> #include <cmath> using namespace std; long long int problem(long long int); int counter = 0; int main() { int i, j; while(cin >> >> j){ int max = 0; if(i > j){ int temp = i; = j; j = temp; } for(long long int count = i; count <= j; count++){ counter = 1; problem(count); if(counter > max) max = counter; } cout << << " " << j << " " << max << endl; } return 0; } long long int problem(long long int n) { if(n == 1){ } else { if(n % 2 == 1){ counter++; return problem(3 * n+1); }else{ counter++; return problem(n/2); } } }
i tried every input provided uva , correct output, however, uva still return me "wrong answer".
thanks lot!
your program okay. print numbers appeared in input. :
input : 10 5
correct output : 10 5 20
your output : 5 10 20
Comments
Post a Comment