关于3n+1问题,求两个数之间最大cycle length
程序代码:#include <stdio.h>
int main()
{
long n1, n2, i, m, n, cnt, maxcycle, tmp;
while(scanf("%ld%ld", &n1, &n2) !=EOF){
if(n1>n2){
tmp=n1;
n1=n2;
n2=tmp;
}
for(i=n1;i>=n2;++i){
i=m=n;
cnt=1;
}
maxcycle=1;
while(n != 1){
if(n % 2)
n=3*n+1;
else
n=n/2;
cnt++;
}
if(cnt>maxcycle) maxcycle=cnt;
}
printf("%ld%ld%ld\n", m, n, maxcycle);
return 0;
}
版主大人指责我傲慢,那么我知错能改。
输入两个数,两个数字分别要判断是奇数偶数。
当奇数时,程式执行运算3*n+1。
当为偶数时,程式执行运算n/2。
将得出的结果反复执行上列运算,直到得到数字1时停止。
例如输入 22, 得到的数列: 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1
22 的 cycle length为 16
这个程式是想要找出输入的两个数字之间产生的最大cycle length。
在我编译完成这个程式后,输入资料
1 10 与 10 1 与 900 1000皆没有得到任何输出结果
如图所示
请问这是哪里发生了错误??
[此贴子已经被作者于2016-9-27 15:22编辑过]










