結果
問題 | No.2181 LRM Question 2 |
ユーザー | 👑 rin204 |
提出日時 | 2023-01-07 01:50:35 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 250 ms / 2,000 ms |
コード長 | 9,351 bytes |
コンパイル時間 | 2,793 ms |
コンパイル使用メモリ | 216,236 KB |
実行使用メモリ | 17,220 KB |
最終ジャッジ日時 | 2024-05-08 01:24:03 |
合計ジャッジ時間 | 5,037 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 230 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 234 ms
5,376 KB |
testcase_09 | AC | 204 ms
5,376 KB |
testcase_10 | AC | 242 ms
5,376 KB |
testcase_11 | AC | 250 ms
5,376 KB |
testcase_12 | AC | 243 ms
5,376 KB |
testcase_13 | AC | 3 ms
5,376 KB |
testcase_14 | AC | 213 ms
17,220 KB |
testcase_15 | AC | 9 ms
5,376 KB |
testcase_16 | AC | 162 ms
13,968 KB |
testcase_17 | AC | 4 ms
5,376 KB |
testcase_18 | AC | 3 ms
5,376 KB |
testcase_19 | AC | 4 ms
5,376 KB |
testcase_20 | AC | 51 ms
6,656 KB |
testcase_21 | AC | 32 ms
5,376 KB |
testcase_22 | AC | 5 ms
5,376 KB |
testcase_23 | AC | 1 ms
5,376 KB |
testcase_24 | AC | 2 ms
5,376 KB |
testcase_25 | AC | 1 ms
5,376 KB |
ソースコード
#line 1 "A.cpp" #include<bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; template <class T> using pq = priority_queue<T>; template <class T> using qp = priority_queue<T, vector<T>, greater<T>>; #define vec(T, A, ...) vector<T> A(__VA_ARGS__); #define vvec(T, A, h, ...) vector<vector<T>> A(h, vector<T>(__VA_ARGS__)); #define vvvec(T, A, h1, h2, ...) vector<vector<vector<T>>> A(h1, vector<vector<T>>(h2, vector<T>(__VA_ARGS__))); #define endl "\n" #define spa ' ' #define len(A) A.size() #define all(A) begin(A), end(A) #define fori1(a) for(ll _ = 0; _ < (a); _++) #define fori2(i, a) for(ll i = 0; i < (a); i++) #define fori3(i, a, b) for(ll i = (a); i < (b); i++) #define fori4(i, a, b, c) for(ll i = (a); ((c) > 0 || i > (b)) && ((c) < 0 || i < (b)); i += (c)) #define overload4(a, b, c, d, e, ...) e #define fori(...) overload4(__VA_ARGS__, fori4, fori3, fori2, fori1)(__VA_ARGS__) #define INT(...) int __VA_ARGS__; inp(__VA_ARGS__); #define LL(...) ll __VA_ARGS__; inp(__VA_ARGS__); #define STRING(...) string __VA_ARGS__; inp(__VA_ARGS__); #define CHAR(...) char __VA_ARGS__; inp(__VA_ARGS__); #define VEC(T, A, n) vector<T> A(n); inp(A); #define VVEC(T, A, n, m) vector<vector<T>> A(n, vector<T>(m)); inp(A); const ll MOD1 = 1000000007; const ll MOD9 = 998244353; template<class T> auto min(const T& a){ return *min_element(all(a)); } template<class T> auto max(const T& a){ return *max_element(all(a)); } template <class T, class S> inline bool chmax(T &a, const S &b) { return (a < b ? a = b, 1 : 0); } template <class T, class S> inline bool chmin(T &a, const S &b) { return (a > b ? a = b, 1 : 0); } void print(){cout << endl;} template <class Head, class... Tail> void print(Head &&head, Tail &&... tail) { cout << head; if (sizeof...(Tail)) cout << spa; print(forward<Tail>(tail)...); } template<typename T> void print(vector<T> &A){ int n = A.size(); for(int i = 0; i < n; i++){ cout << A[i]; if(i == n - 1) cout << endl; else cout << spa; } } template<typename T> void print(vector<vector<T>> &A){ for(auto &row: A) print(row); } template<typename T, typename S> void print(pair<T, S> &A){ cout << A.first << spa << A.second << endl; } template<typename T, typename S> void print(vector<pair<T, S>> &A){ for(auto &row: A) print(row); } template<typename T, typename S> void prisep(vector<T> &A, S sep){ int n = A.size(); for(int i = 0; i < n; i++){ cout << A[i]; if(i == n - 1) cout << endl; else cout << sep; } } template<typename T, typename S> void priend(T A, S end){ cout << A << end; } template<typename T> void priend(T A){ priend(A, spa); } template<class... T> void inp(T&... a){ (cin >> ... >> a); } template<typename T> void inp(vector<T> &A){ for(auto &a:A) cin >> a; } template<typename T> void inp(vector<vector<T>> &A){ for(auto &row:A) inp(row); } template<typename T, typename S> void inp(pair<T, S> &A){ inp(A.first, A.second); } template<typename T, typename S> void inp(vector<pair<T, S>> &A){ for(auto &row: A) inp(row.first, row.second); } template<typename T> T sum(vector<T> &A){ T tot = 0; for(auto a:A) tot += a; return tot; } #line 2 "Library/C++/math/pollard_rho.hpp" #line 2 "Library/C++/math/modpow.hpp" template<typename T> T modpow(T a, long long b, T MOD){ T ret = 1; while(b > 0){ if(b & 1){ ret *= a; ret %= MOD; } a *= a; a %= MOD; b >>= 1; } return ret; } #line 3 "Library/C++/math/millerRabin.hpp" bool isPrime(long long n){ if(n <= 1) return false; else if(n == 2) return true; else if(n % 2 == 0) return false; long long A[7] = {2, 325, 9375, 28178, 450775, 9780504, 1795265022}; long long s = 0; long long d = n - 1; while(d % 2 == 0){ d /= 2; s++; } for(auto a: A){ if(a % n == 0) return true; long long x = modpow<__int128_t>(a, d, n); if(x != 1){ bool ng = true; for(int i = 0; i < s; i++){ if(x == n - 1){ ng = false; break; }; x = __int128_t(x) * x % n; } if(ng) return false; } } return true; } #line 4 "Library/C++/math/pollard_rho.hpp" long long pollard(long long N) { if (N % 2 == 0) return 2; if (isPrime(N)) return N; auto f = [&](long long x) -> long long { return (__int128_t(x) * x + 1) % N; }; long long step = 0; while (true) { ++step; long long x = step, y = f(x); while (true) { long long p = gcd(y - x + N, N); if (p == 0 || p == N) break; if (p != 1) return p; x = f(x); y = f(f(y)); } } } vector<long long> primefact(long long N) { if (N == 1) return {}; long long p = pollard(N); if (p == N) return {p}; vector<long long> left = primefact(p); vector<long long> right = primefact(N / p); left.insert(left.end(), right.begin(), right.end()); sort(left.begin(), left.end()); return left; } #line 2 "Library/C++/math/modinv.hpp" template<typename T> T modinv(T a, T MOD){ T b = MOD; T u = 1; T v = 0; while(b > 0){ T t = a / b; a -= t * b; u -= t * v; swap(a, b); swap(u, v); } if(a != 1) return -1; if(u < 0) u += MOD; return u; } #line 2 "Library/C++/math/ext_gcd.hpp" template<typename T> vector<T> ext_gcd(T a, T b){ // return (x, y, gcd(a, b)) s.t. ax + by = gcd(a, b) if(a == 0) return {0, 1, b}; else{ auto tmp = ext_gcd(b % a, a); T x = tmp[0]; T y = tmp[1]; T g = tmp[2]; return {y - b / a * x, x, g}; } } #line 3 "Library/C++/math/Garner.hpp" pair<long long, long long> Garner(vector<long long> &R, vector<long long> &M){ int n = R.size(); long long r = 0; long long m = 1; for(int i = 0; i < n; i++){ long long ri = R[i]; long long mi = M[i]; if(ri < 0 || mi <= ri){ ri = (ri % mi + mi) % mi; } if(m < mi){ swap(m, mi); swap(r, ri); } if(m % mi == 0){ if(r % mi != ri) return {0, 0}; continue; } long long g, im; auto res = ext_gcd(m, mi); g = res[2]; im = res[0]; // print(m, mi, im, g); if(im < 0) im += mi; long long ui = mi / g; if((ri - r) % g != 0) return {0, 0}; long long x = (ri - r) / g % ui * im % ui; r += x * m; m *= ui; if (r < 0) r += m; } return {r, m}; } #line 6 "Library/C++/math/arbitrary_mod_nCk.hpp" struct prime_power_mod_nCk{ int p, e, m; vector<long long> fact, invfact; prime_power_mod_nCk(int p, int e): p(p), e(e){ m = 1; for(int i = 0; i < e; i++) m *= p; fact.resize(m + 1); invfact.resize(m + 1); fact[0] = 1; invfact[0] = 1; for(long long i = 1; i <= m; i++){ if(i % p == 0) fact[i] = fact[i - 1]; else fact[i] = fact[i - 1] * i % m; invfact[i] = modinv<long long>(fact[i], m); } } long long C(long long n, long long k){ if(n < 0 || n < k || k < 0) return 0; long long ret = 1; long long r = n - k; int e0 = 0, eq = 0, i = 0; while(n > 0){ ret = ret * fact[n % m] % m; ret = ret * invfact[k % m] % m; ret = ret * invfact[r % m] % m; n /= p; k /= p; r /= p; e0 += n - k - r; if(e0 >= e) return 0; i++; if(i >= e) eq += n - k - r; } if(!(p == 2 && e >= 3) && (eq & 1)){ ret = ret * (m - 1) % m; } ret *= modpow<long long>(p, e0, m); return ret % m; } }; struct arbitrary_mod_nCk{ int MOD; vector<long long> M; vector<prime_power_mod_nCk> prime_nCk; arbitrary_mod_nCk(int MOD) : MOD(MOD){ if(MOD == 1) return; auto primes = primefact(MOD); int row = 0; int bef = primes[0]; primes.push_back(-1); for(auto p:primes){ if(p == bef) row++; else{ int x = 1; for(int i = 0; i < row; i++){ x *= bef; } M.push_back(x); prime_nCk.push_back(prime_power_mod_nCk(bef, row)); bef = p; row = 1; } } } long long nCk(long long n, long long k){ if(MOD == 1) return 0; vector<long long> R(M.size()); for(int i = 0; i < M.size(); i++){ R[i] = prime_nCk[i].C(n, k); } return Garner(R, M).first; } }; #line 125 "A.cpp" void solve(){ LL(L, R, M); arbitrary_mod_nCk C(M); ll ans = 0; fori(i, L, R + 1){ ans += C.nCk(2 * i, i) - 2; ans %= M; } if(ans < 0) ans += M; print(ans); } int main(){ cin.tie(0)->sync_with_stdio(0); int t; t = 1; // cin >> t; while(t--) solve(); return 0; }