3N+1Problem/신재동

~cpp 
#include <iostream>
using namespace std;

int getCount(int aNumber)
{
	int count = 0;
	while(true)
	{
		count++;
		if(aNumber == 1)
			break;
		else
		{
			if(aNumber % 2 == 1)
				aNumber = 3 * aNumber + 1;
			else
				aNumber = aNumber / 2;
		}
	}
	return count;
}

int getMaxCount(int aStart, int aFinish)
{
	int maxCount = 0;
	for(int i =aStart; i < aFinish; i++)
	{
		int count = getCount(i);
		
		if(maxCount < count)
			maxCount = count;
	}
	return maxCount;
}

int main()
{
	int start, finish;
	cin >> start >> finish;

	int maxCount = getMaxCount(start, finish);

	cout << maxCount << endl;
	return 0;
}

심심해서... 오랫만에 C++하니까 어리버리하다. --재동
시간초과. 다시 푸세요.ㅋㅋ --Leonardong

Retrieved from http://wiki.zeropage.org/wiki.php/3N+1Problem/신재동
last modified 2021-02-07 05:22:16