¶
2005/02/18 Accepted 0:03.725 440
한 해 하 .
(1, 999999) 해 행 .
한 해 하 .
(1, 999999) 해 행 .
¶
~cpp
// no100 - The 3n+1 Problem
#include <iostream>
using namespace std;
int findMaxCycle(int a, int b);
int main()
{
int a, b; //
while (cin >> a >> b)
{
int maxCycle = findMaxCycle(a, b); // 클
cout << a << " " << b << " " << maxCycle << endl;
}
return 0;
}
int findMaxCycle(int a, int b)
{
if (a > b)
{
int t;
t = a;
a = b;
b = t;
}
int nCycle; // 클
long temp; // 32트 .
int maxCycle = 0; // 클
if (a == 1 && b == 1)
return 1;
else if (a == 1)
a++;
int i;
for (i=a; i<=b; i++)
{
nCycle = 1;
temp = i;
while (true)
{
if (temp % 2 == 0)
{
temp /= 2;
nCycle++;
if (temp == 1)
break;
}
else
{
temp = (3 * temp + 1) / 2;
nCycle += 2;
}
}
if (maxCycle < nCycle)
maxCycle = nCycle;
}
return maxCycle;
}










