标签:
Step1:对每组待测资料必须输出它为第几组(从1开始),一个冒号,首项A的值,上限L的值,以及此一数列的项数。
#include<stdio.h> int main() {long n,m,i,A,t=1; while(scanf("%ld%ld",&n,&m)!=EOF){ A=n; if(n<0&&m<0) break; if(n==1) break; for(i=0;;){ if(n%2==0) {n/=2;i++;} else {n=(3*n+1);i++;} if(n>m) break; if(n==1) {i++;break;} } printf("Case %ld: A = %ld, limit = %ld, number of terms = %ld\n",t,A,m,i); t++; } return 0; }
UVa694 - The Collatz Sequence(模拟)
标签:
原文地址:http://blog.csdn.net/a197p/article/details/45588331