problem 100---The 3n + 1 problem(UVA)----2005/4/15

Dear Gilbert_Lee: You are trying to solve "The 3n + 1 problem" (problem 100). I have received and stored your C program. It will be compiled and run as soon as possible; please be patient waiting for the results... -- The Online Judge --------------- The program I'll compile begins here: --------------- /* Author: Gilbert_Lee Email: Gilbert_Lee@163.com Date: 2006-4-8 Address:Sichuan University @ Zhulin cun Website:http://online-judge.uva.es/p/v1/100.html Problem_100 */ #include void main() { int a, b, result, i, temp, k, m, n; while(scanf("%d%d", &a, &b) == 2) { result = 0; if(a > b) { m = b; n = a; } else { m = a; n = b; } for(i = m; i <= n; i++) { temp = 0; k = i; while(1) { temp++; if(k == 1) { break; } else if(k%2 == 1) { k = k*3 + 1; } else if(k%2 == 0) { k = k/2; } } if(result < temp) { result = temp; } } printf("%d %d %d/n", a, b, result); } }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值