From d08435a24bffb062bda3e0aa6f8b25451c6c19d8 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Mon, 5 Sep 2022 14:46:37 +0800 Subject: [PATCH] =?UTF-8?q?P4317=20=E8=8A=B1=E7=A5=9E=E7=9A=84=E6=95=B0?= =?UTF-8?q?=E8=AE=BA=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.luogu.com.cn/record/85935689 --- Luogu/P4317/P4317.cpp | 57 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 Luogu/P4317/P4317.cpp diff --git a/Luogu/P4317/P4317.cpp b/Luogu/P4317/P4317.cpp new file mode 100644 index 00000000..6eff10f7 --- /dev/null +++ b/Luogu/P4317/P4317.cpp @@ -0,0 +1,57 @@ +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 65; +const int mod = 1e7 + 7; + +long long n, f[N][N][2], ans = 1; +std::bitset<65> b; + +long long binpow(long long a, long long b) { + a %= mod; + + long long res = 1; + + while (b) { + if (b & 1) res = res * a % mod; + a = a * a % mod; + b >>= 1; + } + + return res; +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> n; + + for (int i = 0; i < 64; i++) { + b.set(64 - i, (n >> i) & 1); + } + + f[0][0][1] = 1; + + for (int i = 0; i < 64; i++) { + for (int j = 0; j <= i; j++) { + f[i + 1][j][0] += f[i][j][0]; + f[i + 1][j + 1][0] += f[i][j][0]; + f[i + 1][j][(b[i + 1] == 0)] += f[i][j][1]; + if (b[i + 1] == 1) f[i + 1][j + 1][1] += f[i][j][1]; + } + } + + for (int i = 1; i <= 64; i++) { + ans = ans * binpow(i, f[64][i][0] + f[64][i][1]) % mod; + } + + cout << ans << endl; + + return 0; +}