~cpp
#include <iostream>
using namespace std;

int countNum, cycle, i, start, end;

int cycleNumber(int number)
{
	countNum=1;
	while(number!=1)
	{
		if(number%2==0)
		{
			number /=2;
			countNum++;
		}
		else
		{
			number = (3*number +1)/2;
			countNum+=2;
		}
	}
	return countNum;
}

int maxCycle(int start, int end)
{
	cycle=0;
	for(i=start; i<=end; i++)
		if(cycleNumber(i)>cycle)
			cycle = cycleNumber(i);
	return cycle;
}

int main()
{
	while(cin>>start>>end)
	{
		if(start>end)
			cout << start << " " << end << " " << maxCycle(end, start) << endl;
		else
			cout << start << " " << end << " " << maxCycle(start, end) << endl;
	}
	return 0;
}
Retrieved from http://wiki.zeropage.org/wiki.php/3n 1/Celfin
last modified 2021-02-07 05:22:17