0
点赞
收藏
分享

微信扫一扫

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

唯米天空 2023-04-11 阅读 27


/*
 * UVA_694.cpp
 *
 *  Created on: 2013年10月6日
 *      Author: Administrator
 */

#include <stdio.h>

int main(){
	long long a,l;//不要用int
	int 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;
}



举报

相关推荐

0 条评论