Submission #1781318
Source Code Expand
__int128_t #include <bits/stdc++.h> using namespace std; ostream &operator<<(ostream &os, __int128_t value) { if (ostream::sentry(os)) { __uint128_t tmp = value < 0 ? -value : value; char buffer[64]; char *d = end(buffer); do { --d; *d = "0123456789"[tmp % 10]; tmp /= 10; } while (tmp != 0); if (value < 0) { --d; *d = '-'; } __int128_t len = end(buffer) - d; if (os.rdbuf()->sputn(d, len) != len) { os.setstate(ios_base::badbit); } } return os; } istream &operator>>(istream &is, __int128_t &value) { string in; is >> in; value = 0; for (const char &c : in) { if ('0' <= c && c <= '9') value = 10 * value + (c - '0'); } if (in[0] == '-') value *= -1; return is; } const __int128_t mod = 1777777777; struct ModCombination { ModCombination(unsigned __int128_t n) : n(n), F(n + 1, 1), I(n + 1, 1) { for (__int128_t i = 1; i <= n; ++i) F[i] = 1ll * i * F[i - 1] % mod; for (__int128_t i = mod - 2, j = F[n]; i; i >>= 1) { if (i & 1) I[n] = I[n] * j % mod; j = j * j % mod; } for (__int128_t i = n - 1; i; --i) I[i] = I[i + 1] * (i + 1ll) % mod; } unsigned __int128_t n; vector<int> F, I; __int128_t operator()(__int128_t p, __int128_t k) { if (p > n) exit(-1); if (k > p) return 0; return 1ll * F[p] * I[k] % mod * I[p - k] % mod; } }; __int128_t mod_pow(__int128_t a, __int128_t x, __int128_t p = 1e9 + 7) { __int128_t ret = 1; for (__int128_t i = 1ll << 60; i; i >>= 1) { ret *= ret; ret %= p; if (x & i) { ret *= a; ret %= p; } } return ret; } __int128_t inv(__int128_t n, __int128_t p = 1e9 + 7) { return mod_pow(n, p - 2, p); } signed main() { __int128_t n, k; cin >> n >> k; vector<__int128_t> fact(k + 1, 1); for (__int128_t i = 1; i < fact.size(); ++i) { fact[i] *= i * fact[i - 1]; fact[i] %= mod; } ModCombination mc(k); __int128_t t = 0; for (__int128_t i = 0; i <= k; ++i) { t += (mc(k, i) * fact[k - i] % mod) * (i & 1 ? -1 : 1); t %= mod; } __int128_t a = 1; for (__int128_t i = 0; i < k; ++i) { a *= n - i; a %= mod; } a *= inv(fact[k], mod); a %= mod; cout << a * t % mod << endl; }
Submission Info
Submission Time | |
---|---|
Task | C - 高橋君、24歳 |
User | Luzhiled |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 2358 Byte |
Status | CE |
Compile Error
./Main.cpp:1:12: error: stray ‘#’ in program __int128_t #include <bits/stdc++.h> ^ ./Main.cpp:1:21: error: expected initializer before ‘<’ token __int128_t #include <bits/stdc++.h> ^ ./Main.cpp:4:1: error: ‘ostream’ does not name a type ostream &operator<<(ostream &os, __int128_t value) { ^ ./Main.cpp:26:1: error: ‘istream’ does not name a type istream &operator>>(istream &is, __int128_t &value) { ^ ./Main.cpp:39:38: error: expected ‘,’ or ‘...’ before ‘n’ ModCombination(unsigned __int128_t n) : n(n), F(n + 1, 1), I(n + 1, 1) { ^ ./Main.cpp:48:12: error: expected ‘;’ at end of member declaration unsigned __int128_t n; ^ ./Main.cpp:48:23: error: ‘n’ does not name a type unsigned __int128_t n; ^ ./Main.cpp:49:3: error: ‘vector’ does not name a type vector<int> F, I; ^ ./Main.cpp:51:3: error: ‘__int128_t’ does not name a type __int128_t operator()(__int128_t p, __int128_t k) {...