Uva 694 The 3n + 1 problem

/* coder: ACboy date: 2010-2-15 */ #include <iostream> using namespace std; int main() { long a, b; long size; int n; n = 0; freopen("694.txt", "r", stdin); while (cin >> a >> b) { long temp = a; if (a < 0 && b < 0) { break; } else { size = 0; while (a != 1) { if (a % 2 == 0) a /= 2; else a = a * 3 + 1; if (a > b) break; size++; } cout << "Case " << ++n << ": A = " << temp << ", limit = " << b << ", number of terms = " << size + 1 << endl; } } }

你可能感兴趣的:(Date,2010)