U E D R , A S I H C RSS

The Priest Mathematician/문보창

2006-01-11 Accepted 0.688 14280
{{| 0.5a(a + 1) ≤ n, (a ≥ 0 고, 는 가 ) |}}
그렇다면 력 n 과 같 된다. a를 n 바꿀 까?
{{| T(n) = 2<sup>a</sup>(a - 1) + 1 + 2<sup>a</sup>{n - 0.5 a ( a + 1 ) } |}}

p.s. 는 k 개 려고 노력나, 리는 k 다. 리가 는 것 k 를 는 것 기는 를 구는 것다.

~cpp
// 10254 - The Priest Mathematician
#include "BigInteger.h"
using namespace BigMath;

int findK(int n)
{
	int i;
	for (i = 0; ; i++)
		if (0.5 * i * (i + 1) > n)
			break;
	return i - 1;
}

void process(int n)
{
	if (n == 0)
	{
		cout << 0 << endl;
		return;
	}
	int k, temp;
	BigInteger result, kpow2(2);
	k = findK(n);
	temp = n - 0.5 * k * (k + 1);
	kpow2 = kpow2.Power(k);
	result = kpow2 * (k - 1) + 1 + temp * kpow2;
	cout << result << endl;
}

int main()
{
	int n;
	while (cin >> n)
		process(n);
	return 0;
}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:28:13
Processing time 0.0075 sec