solution.cpp 1.0 KB
Newer Older
每日一练社区's avatar
每日一练社区 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 100000;
ll s[maxn + 10], dp[maxn + 10], inv[maxn + 10], f[maxn + 10];
ll n;
ll mod = 1000000009;
ll qPow(ll a, ll b)
{
    ll ans = 1;
    while (b != 0)
    {
        if (b & 1)
        {
            ans = ans * a % mod;
        }
        a = a * a % mod;
        b >>= 1;
    }
    return ans % mod;
}
ll C(ll n, ll m)
{
    return (f[n] * inv[f[m]]) % mod * inv[f[n - m]] % mod;
}
int main()
{
    cin >> n;
    f[0] = 1;
    for (int i = 1; i <= maxn; i++)
    {
        f[i] = (f[i - 1] * i) % mod;
        inv[i] = qPow(i, mod - 2);
    }
    for (int i = n; i >= 1; i--)
    {
        s[i] = (s[i * 2 + 1] <= n ? s[i * 2 + 1] : 0) + (s[i * 2] <= n ? s[i * 2] : 0) + 1;
    }
    for (int i = 1; i <= n; i++)
    {
        dp[i] = 1;
    }
    for (int i = n; i >= 1; i--)
    {
        if (i * 2 + 1 <= n)
        {
            dp[i] = (C(s[i], s[i * 2]) * dp[i * 2]) % mod * dp[i * 2] % mod;
        }
    }
    cout << dp[1] << endl;
    return 0;
}