Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

3n 1/Celfin

From ZeroWiki
Revision as of 05:22, 7 February 2021 by imported>Unknown
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
#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;
}