Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int arr[1000000]; // arr[i] = length of chain of starting with i
- int main()
- {
- long temp;
- int count, max = 0, maxInd;
- for(int i = 1; i < 1000000; i++){
- temp = i;
- count = 0;
- while(temp!=1){
- if(temp < i){
- count+=arr[temp];
- break;
- } else {
- if(temp%2== 0) temp/=2;
- else temp = 3*temp+1;
- }
- count++;
- }
- arr[i] = count;
- if(count > max){
- max = count;
- maxInd = i;
- }
- }
- cout << maxInd << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement