Created
April 5, 2014 09:14
-
-
Save mkawserm/9989460 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/* | |
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