You are viewing a single comment's thread. Return to all comments →
int main() {
int t; scanf("%d ",&t); int ans[5000001] ={0}; int max_count=-1; int steps = 1; for(long i=1;i<=5000000;i++){ unsigned long num=i; int count = 0; while(num!=1){ if(num%2 == 0) num= num/2; else num= 3*num+1; count++; } if(count>=max_count) { max_count = count; steps = i; } ans[i] = steps; } while(t--){ int n; scanf("%d",&n); printf("%d\n",ans[n]); } return 0;
}
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #14: Longest Collatz sequence
You are viewing a single comment's thread. Return to all comments →
c code
int main() {
}