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.0131 sec