No older revisions available
No older revisions available
소감 ¶
{{| 2006.1.6 8.842s |}}
코드 ¶
~cpp #include <iostream> using namespace std; int count = 0; int i, j; bool input() { count = 0; if (cin >> i >> j) return true; return false; } int process(int n) { count++; if(n == 1) { return count; } else if(n % 2 == 1) { n = 3 * n + 1; return process(n); } else { n /= 2; return process(n); } } int compare() { int temp; int temp2; if(i == j) return process(i); else { temp = 0; count = 0; if(i > j) { for(int k = j; k <= i; k++) { temp2 = process(k); count = 0; if(temp <= temp2) { temp = temp2; } } } else { for(int k = i; k <= j; k++) { temp2 = process(k); count = 0; if(temp <= temp2) { temp = temp2; } } } return temp; } } int main() { while(input()) { int temp= compare(); cout << i << " " << j << " " << temp << endl;; } return 0; }