Skip to content

Instantly share code, notes, and snippets.

@mkawserm
Created April 5, 2014 09:14
Show Gist options
  • Save mkawserm/9989460 to your computer and use it in GitHub Desktop.
Save mkawserm/9989460 to your computer and use it in GitHub Desktop.
/*
Author : kawser
Author blog : http://blog.kawser.org
Problem ID : 100
Time Limit : 3s
OJ Link : http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=36
*/
#include <iostream>
using namespace std;
int main (void){
int n , i , j;
while( cin>>i>>j ){
int tempI = i;
int tempJ = j;
if( i>j ) swap(i,j);
int maxCycle = 0;
int Cycle;
while(i <= j){
n = i;
Cycle = 1;
while(n!=1){
if(n%2!=0) n=(3*n)+1;
else n = n/2;
Cycle++;
}
if(Cycle > maxCycle) maxCycle = Cycle;
i++;
}
cout<<tempI<<" "<<tempJ<<" "<<maxCycle<<endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment