U E D R , A S I H C RSS

3N+1 Problem/신재동

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

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2009-05-27 07:09:19
Processing time 0.0071 sec