Language: C++ 4.8.2
#include<stdio.h> int main(void) { long long int m, n, copy_m; int count = 1; int number = 0; while(1) { scanf("%lld%lld", &m, &n); // uva要求用%lld读入有符号长整型 if(m < 0 && n < 0) break; count = 1; copy_m = m; while(m != 1) { if(m % 2 == 0) m = m / 2; else { m = 3*m + 1; if(m > n) break; } count++; } number++; printf("Case %d: A = %lld, limit = %lld, number of terms = %d\n", number, copy_m, n, count); // 注意输出格式,数据类型不统一的话,MingW下会出现莫名奇妙的错误。 } return 0; }
时间: 2024-10-13 00:24:57