Skip to content

Instantly share code, notes, and snippets.

@AhmedKamal
Created May 18, 2015 22:24
Show Gist options
  • Save AhmedKamal/d4e018f7254e3f5054d0 to your computer and use it in GitHub Desktop.
Save AhmedKamal/d4e018f7254e3f5054d0 to your computer and use it in GitHub Desktop.
#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