不难发现在过程中有很多出现过的数,直接记忆化一下就好。。。

#include <bits/stdc++.h>

using namespace std;

int main(){
	int _=1000000;
	map<long long,long long> mp;
	int mx=0;
	int ans=0;
	for(long long i=1;i<=_;++i){
		long long tmp=i;
		int cnt=0;
		while(tmp!=1){
			if(mp[tmp]!=0){
				cnt=cnt+mp[tmp];
				break;
			}
			if(tmp&1) tmp=tmp*3+1;
			else tmp/=2;
			cnt++;
		}
		if(cnt>mx){
			mx=cnt;
			ans=i;
		}
		mp[i]=cnt;
	}	
	printf("%d\n",ans);
	return 0;
}