2006-01-11 Accepted 0.688 14280 |
~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; }