本道题目我没有账号请求那位有账号的大佬帮我交一下看看对不对?必关
#include<bits/stdc++.h>
using namespace std;
int l,r;
int a[10000005];
int check(int x){
if(x == 1){
return 0;
}
if(a[x] != 0){
return a[x];
}
if(x % 2 == 0){
a[x] = check(x / 2) + 1;
}else{
a[x] = check(x * 3 + 1) + 1;
}
return a[x];
}
int main(){
while(cin >> l >> r && l && r){
if(l > r)swap(l , r);
int x = 0,maxn = 0;
for(int i = l ; i <= r ; i ++){
a[i] = check(i);
if(maxn < a[i]){
maxn = a[i];
x = i;
}
}
printf("Between %d and %d, %d generates the longest sequence of %d values.\n" , l , r , x , maxn);
}
return 0;
}