数字本身也正在运行次数类,所以最后的max要加1
每次循环结束记得要k归0,
最大值也要归零
#include<iostream>
using namespace std;
int main()
{
long long i,n, m, t, s, max=0,k = 0;
while (cin >> n >> m)
{
cout << n << ' ' << m << ' ';
t = n;
if (n > m) n = m, m = t;
for ( i = n; i <=m; i++)
{
s = i;
while (s != 1)
{
if (s % 2 == 0)s = s / 2;
else s = 3 * s + 1;
k++;
}
if (max < k) max = k;
k = 0;
}
cout << max+1 << endl;
max = 0;
}
return 0;
}
0.0分
0 人评分