读书人

(1.1.5)UVA 694 The Collatz Sequen

发布时间: 2013-10-09 22:26:11 作者: rapoo

(1.1.5)UVA 694 The Collatz Sequence (直叙式模拟)

/* * UVA_694.cpp * *  Created on: 2013年10月6日 *      Author: Administrator */#include <stdio.h>int main(){long long a,l;//不要用intint counter = 1;while(scanf("%lld%lld",&a,&l)!=EOF,a!=-1 || l!= -1){long long a1 = a;int count = 1;while(a != 1 ){if( a%2 == 0 ){a /= 2;}else{a = 3*a + 1;}if(a > l){break;}count++;}printf("Case %d: A = %lld, limit = %lld, number of terms = %d\n",counter++,a1,l,count);}return 0;}

读书人网 >编程

热点推荐