U E D R , A S I H C RSS

3n 1/Celfin

~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;
}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:22:17
Processing time 0.0079 sec