You are viewing a single comment's thread. Return to all comments →
Can anyone help reduce runtime of this code
#include <cmath> #include <cstdio> #include <vector> #include <iostream> #include <algorithm> using namespace std; int ColSeq(int x){ int count = 0; while(x>1){ if(x%2==0) x /= 2; else x = 3*x + 1; count++; } return count; } int main() { int t; scanf("%d",&t); while(t--){ int n; scanf("%d",&n); int res; int max_res = 0; int max_x; for(int i=n;i>2;i++){ res = ColSeq(i); if(res>max_res){ max_res = res; max_x = i; } } printf("%d\n",max_x); } 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 →
Can anyone help reduce runtime of this code