結果
問題 | No.2613 Sum of Combination |
ユーザー | apricity |
提出日時 | 2024-01-19 22:36:02 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 190 ms / 4,500 ms |
コード長 | 4,870 bytes |
コンパイル時間 | 2,792 ms |
コンパイル使用メモリ | 177,996 KB |
実行使用メモリ | 25,504 KB |
最終ジャッジ日時 | 2024-09-28 04:50:18 |
合計ジャッジ時間 | 8,824 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 14 ms
8,064 KB |
testcase_01 | AC | 13 ms
8,064 KB |
testcase_02 | AC | 16 ms
8,320 KB |
testcase_03 | AC | 13 ms
8,160 KB |
testcase_04 | AC | 13 ms
8,028 KB |
testcase_05 | AC | 14 ms
8,064 KB |
testcase_06 | AC | 14 ms
8,156 KB |
testcase_07 | AC | 14 ms
7,936 KB |
testcase_08 | AC | 13 ms
8,064 KB |
testcase_09 | AC | 14 ms
8,160 KB |
testcase_10 | AC | 14 ms
8,064 KB |
testcase_11 | AC | 14 ms
8,028 KB |
testcase_12 | AC | 15 ms
8,028 KB |
testcase_13 | AC | 19 ms
8,424 KB |
testcase_14 | AC | 19 ms
8,448 KB |
testcase_15 | AC | 18 ms
8,448 KB |
testcase_16 | AC | 19 ms
8,412 KB |
testcase_17 | AC | 19 ms
8,448 KB |
testcase_18 | AC | 18 ms
8,412 KB |
testcase_19 | AC | 22 ms
8,676 KB |
testcase_20 | AC | 14 ms
7,936 KB |
testcase_21 | AC | 13 ms
7,936 KB |
testcase_22 | AC | 24 ms
8,796 KB |
testcase_23 | AC | 172 ms
23,916 KB |
testcase_24 | AC | 175 ms
23,716 KB |
testcase_25 | AC | 166 ms
22,320 KB |
testcase_26 | AC | 183 ms
25,300 KB |
testcase_27 | AC | 98 ms
16,784 KB |
testcase_28 | AC | 176 ms
25,220 KB |
testcase_29 | AC | 183 ms
24,576 KB |
testcase_30 | AC | 188 ms
25,180 KB |
testcase_31 | AC | 183 ms
24,500 KB |
testcase_32 | AC | 179 ms
24,348 KB |
testcase_33 | AC | 179 ms
25,376 KB |
testcase_34 | AC | 183 ms
25,372 KB |
testcase_35 | AC | 190 ms
25,380 KB |
testcase_36 | AC | 186 ms
25,380 KB |
testcase_37 | AC | 182 ms
25,380 KB |
testcase_38 | AC | 181 ms
25,028 KB |
testcase_39 | AC | 180 ms
25,072 KB |
testcase_40 | AC | 176 ms
25,152 KB |
testcase_41 | AC | 181 ms
25,268 KB |
testcase_42 | AC | 188 ms
25,124 KB |
testcase_43 | AC | 178 ms
25,376 KB |
testcase_44 | AC | 176 ms
25,376 KB |
testcase_45 | AC | 14 ms
8,028 KB |
testcase_46 | AC | 14 ms
8,064 KB |
testcase_47 | AC | 14 ms
8,032 KB |
testcase_48 | AC | 14 ms
8,156 KB |
testcase_49 | AC | 13 ms
8,032 KB |
testcase_50 | AC | 174 ms
25,436 KB |
testcase_51 | AC | 176 ms
25,504 KB |
ソースコード
#include<iostream> #include<string> #include<vector> #include<algorithm> #include<numeric> #include<cmath> #include<utility> #include<tuple> #include<cstdint> #include<cstdio> #include<iomanip> #include<map> #include<queue> #include<set> #include<stack> #include<deque> #include<unordered_map> #include<unordered_set> #include<bitset> #include<cctype> #include<chrono> #include<random> #include<cassert> #include<cstddef> #include<iterator> #include<string_view> #include<type_traits> #ifdef LOCAL # include "debug_print.hpp" # define debug(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__) #else # define debug(...) (static_cast<void>(0)) #endif using namespace std; #define rep(i,n) for(int i=0; i<(n); i++) #define rrep(i,n) for(int i=(n)-1; i>=0; i--) #define FOR(i,a,b) for(int i=(a); i<(b); i++) #define RFOR(i,a,b) for(int i=(b-1); i>=(a); i--) #define ALL(v) v.begin(), v.end() #define RALL(v) v.rbegin(), v.rend() #define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ); #define pb push_back using ll = long long; using D = double; using LD = long double; using P = pair<int, int>; template<typename T> using PQ = priority_queue<T,vector<T>>; template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } void yesno(bool flag) {cout << (flag?"Yes":"No") << "\n";} template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; } template<typename T, typename U> istream &operator>>(istream &is, pair<T, U> &p) { is >> p.first >> p.second; return is; } template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { int s = (int)v.size(); for (int i = 0; i < s; i++) os << (i ? " " : "") << v[i]; return os; } template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; } void in() {} template<typename T, class... U> void in(T &t, U &...u) { cin >> t; in(u...); } void out() { cout << "\n"; } template<typename T, class... U, char sep = ' '> void out(const T &t, const U &...u) { cout << t; if (sizeof...(u)) cout << sep; out(u...); } void outr() {} template<typename T, class... U, char sep = ' '> void outr(const T &t, const U &...u) { cout << t; outr(u...); } #include "atcoder/modint.hpp" #include "atcoder/convolution.hpp" using mint = atcoder::modint998244353; constexpr int mod = 998244353; constexpr ll modpow(const ll& a, ll n, ll mod) noexcept { if (n == 0) return 1; auto t = modpow(a, n / 2, mod); t = t * t % mod; if (n & 1) t = t * a % mod; return t; } int calc_primitive_root(int mod) { if (mod == 2) return 1; if (mod == 167772161) return 3; if (mod == 469762049) return 3; if (mod == 754974721) return 11; if (mod == 998244353) return 3; int divs[20] = {}; divs[0] = 2; int cnt = 1; long long x = (mod - 1) / 2; while (x % 2 == 0) x /= 2; for (long long i = 3; i * i <= x; i += 2) { if (x % i == 0) { divs[cnt++] = i; while (x % i == 0) x /= i; } } if (x > 1) divs[cnt++] = x; for (int g = 2;; g++) { bool ok = true; for (int i = 0; i < cnt; i++) { if (modpow(g, (mod - 1) / divs[i], mod) == 1) { ok = false; break; } } if (ok) return g; } } constexpr int mx = 200005; ll fact[mx]; ll inv[mx]; ll finv[mx]; ll p; ll com(int n, int m){ if(n < 0 or m < 0 or n < m) return 0; return (fact[n] * finv[m] * finv[n-m]) % p; } int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); ll n; in(n,p); ll g = calc_primitive_root(p); rep(i,mx) fact[i] = inv[i] = finv[i] = 1; for(int i = 2; i < mx; i++){ fact[i] = fact[i-1] * i % p; inv[i] = (p-inv[p%i]) * (p/i) % p; finv[i] = finv[i-1] * inv[i] % p; } vector<int> nv; while(n > 0){ nv.pb(n%p); n /= p; } reverse(ALL(nv)); int k = nv.size(); vector<ll> pow(p,1); vector<ll> ipow(p); FOR(i,1,p){ pow[i] = pow[i-1]*g%p; ipow[pow[i]] = i%(p-1); } queue<vector<mint>> q; rep(i,k){ vector<mint> c(p-1); rep(j,nv[i]+1){ ll cc = com(nv[i],j); c[ipow[cc]]++; } q.push(c); } while(q.size() > 1){ auto f1 = q.front(); q.pop(); auto f2 = q.front(); q.pop(); q.push(atcoder::convolution(f1,f2)); } mint ans = 0; int m = q.front().size(); rep(i,m){ ll x = pow[i%(p-1)]; ans += q.front()[i] * x; } out(ans.val()); }