acm竞赛第100题答案

时间:2013-10-27 08:35:58
【文件属性】:

文件名称:acm竞赛第100题答案

文件大小:27KB

文件格式:DOC

更新时间:2013-10-27 08:35:58

acm

acm第100题 The 3n+1 problem #include using namespace std; unsigned CyCle(unsigned m) { unsigned count = 1; while (m != 1) { if (m & 0x01) m = 3 * m + 1; else m = m / 2; count++; } return count; } int main() { unsigned i,j; while (scanf("%u %u",&i,&j) != EOF) { unsigned max = 0; unsigned min1,max1; min1 = i < j ? i : j; max1 = i > j ? i : j; for (unsigned k = min1; k <= max1; ++k) if (max < CyCle(k)) max = CyCle(k); cout << i << " " << j << " " << max << endl; } return 0; }


网友评论