Created
May 18, 2015 22:24
-
-
Save AhmedKamal/d4e018f7254e3f5054d0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#include<stdlib.h> | |
#include<iostream> | |
#include<algorithm> | |
using namespace std; | |
int cycleLen(int n){ | |
int cnt = 1; | |
while (n != 1) | |
{ | |
if (n % 2 == 0) | |
{ | |
n /= 2; | |
} | |
else | |
{ | |
n = 3 * n + 1; | |
} | |
cnt++; | |
} | |
return cnt; | |
} | |
int main(){ | |
int x, y; | |
while (cin >> x >> y){ | |
int max = 0; | |
int i; | |
for (i = min(x, y); i <= (int)std::max(x,y); i++) | |
{ | |
int len = cycleLen(i); | |
if (max < len) | |
{ | |
max = len; | |
} | |
//cout << i << endl; | |
} | |
cout << x << " " << y << " " << max << endl; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment