結果
問題 | No.2798 Multiple Chain |
ユーザー | shinchan |
提出日時 | 2024-06-28 21:59:53 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 6 ms / 2,000 ms |
コード長 | 6,801 bytes |
コンパイル時間 | 2,559 ms |
コンパイル使用メモリ | 221,788 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-28 21:59:58 |
合計ジャッジ時間 | 3,599 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,944 KB |
testcase_02 | AC | 2 ms
6,944 KB |
testcase_03 | AC | 2 ms
6,940 KB |
testcase_04 | AC | 2 ms
6,940 KB |
testcase_05 | AC | 2 ms
6,944 KB |
testcase_06 | AC | 2 ms
6,940 KB |
testcase_07 | AC | 2 ms
6,940 KB |
testcase_08 | AC | 1 ms
6,944 KB |
testcase_09 | AC | 2 ms
6,940 KB |
testcase_10 | AC | 2 ms
6,944 KB |
testcase_11 | AC | 2 ms
6,940 KB |
testcase_12 | AC | 1 ms
6,940 KB |
testcase_13 | AC | 2 ms
6,944 KB |
testcase_14 | AC | 1 ms
6,940 KB |
testcase_15 | AC | 2 ms
6,944 KB |
testcase_16 | AC | 1 ms
6,940 KB |
testcase_17 | AC | 3 ms
6,940 KB |
testcase_18 | AC | 2 ms
6,944 KB |
testcase_19 | AC | 2 ms
6,940 KB |
testcase_20 | AC | 2 ms
6,944 KB |
testcase_21 | AC | 1 ms
6,940 KB |
testcase_22 | AC | 2 ms
6,944 KB |
testcase_23 | AC | 0 ms
6,940 KB |
testcase_24 | AC | 1 ms
6,940 KB |
testcase_25 | AC | 2 ms
6,944 KB |
testcase_26 | AC | 1 ms
6,944 KB |
testcase_27 | AC | 2 ms
6,940 KB |
testcase_28 | AC | 2 ms
6,940 KB |
testcase_29 | AC | 2 ms
6,948 KB |
testcase_30 | AC | 2 ms
6,940 KB |
testcase_31 | AC | 2 ms
6,944 KB |
testcase_32 | AC | 2 ms
6,944 KB |
testcase_33 | AC | 2 ms
6,944 KB |
testcase_34 | AC | 6 ms
6,944 KB |
testcase_35 | AC | 2 ms
6,940 KB |
testcase_36 | AC | 2 ms
6,944 KB |
testcase_37 | AC | 2 ms
6,940 KB |
testcase_38 | AC | 2 ms
6,944 KB |
testcase_39 | AC | 2 ms
6,944 KB |
testcase_40 | AC | 2 ms
6,944 KB |
testcase_41 | AC | 1 ms
6,944 KB |
testcase_42 | AC | 2 ms
6,944 KB |
testcase_43 | AC | 2 ms
6,940 KB |
testcase_44 | AC | 2 ms
6,940 KB |
testcase_45 | AC | 2 ms
6,940 KB |
testcase_46 | AC | 2 ms
6,940 KB |
testcase_47 | AC | 2 ms
6,944 KB |
testcase_48 | AC | 2 ms
6,940 KB |
testcase_49 | AC | 1 ms
6,940 KB |
testcase_50 | AC | 2 ms
6,940 KB |
testcase_51 | AC | 2 ms
6,940 KB |
testcase_52 | AC | 2 ms
6,944 KB |
testcase_53 | AC | 2 ms
6,944 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; #define all(v) (v).begin(),(v).end() #define pb(a) push_back(a) #define rep(i, n) for(int i=0;i<n;i++) #define foa(e, v) for(auto& e : v) using ll = long long; const ll MOD7 = 1000000007, MOD998 = 998244353, INF = (1LL << 60); #define dout(a) cout<<fixed<<setprecision(10)<<a<<endl; // montgomery modint (MOD < 2^62, MOD is odd) struct MontgomeryModInt64 { using mint = MontgomeryModInt64; using u64 = uint64_t; using u128 = __uint128_t; // static menber static u64 MOD; static u64 INV_MOD; // INV_MOD * MOD ≡ 1 (mod 2^64) static u64 T128; // 2^128 (mod MOD) // inner value u64 val; // constructor MontgomeryModInt64() : val(0) { } MontgomeryModInt64(long long v) : val(reduce((u128(v) + MOD) * T128)) { } u64 get() const { u64 res = reduce(val); return res >= MOD ? res - MOD : res; } // mod getter and setter static u64 get_mod() { return MOD; } static void set_mod(u64 mod) { assert(mod < (1LL << 62)); assert((mod & 1)); MOD = mod; T128 = -u128(mod) % mod; INV_MOD = get_inv_mod(); } static u64 get_inv_mod() { u64 res = MOD; for (int i = 0; i < 5; ++i) res *= 2 - MOD * res; return res; } static u64 reduce(const u128 &v) { return (v + u128(u64(v) * u64(-INV_MOD)) * MOD) >> 64; } // arithmetic operators mint operator + () const { return mint(*this); } mint operator - () const { return mint() - mint(*this); } mint operator + (const mint &r) const { return mint(*this) += r; } mint operator - (const mint &r) const { return mint(*this) -= r; } mint operator * (const mint &r) const { return mint(*this) *= r; } mint operator / (const mint &r) const { return mint(*this) /= r; } mint& operator += (const mint &r) { if ((val += r.val) >= 2 * MOD) val -= 2 * MOD; return *this; } mint& operator -= (const mint &r) { if ((val += 2 * MOD - r.val) >= 2 * MOD) val -= 2 * MOD; return *this; } mint& operator *= (const mint &r) { val = reduce(u128(val) * r.val); return *this; } mint& operator /= (const mint &r) { *this *= r.inv(); return *this; } mint inv() const { return pow(MOD - 2); } mint pow(u128 n) const { mint res(1), mul(*this); while (n > 0) { if (n & 1) res *= mul; mul *= mul; n >>= 1; } return res; } // other operators bool operator == (const mint &r) const { return (val >= MOD ? val - MOD : val) == (r.val >= MOD ? r.val - MOD : r.val); } bool operator != (const mint &r) const { return (val >= MOD ? val - MOD : val) != (r.val >= MOD ? r.val - MOD : r.val); } mint& operator ++ () { ++val; if (val >= MOD) val -= MOD; return *this; } mint& operator -- () { if (val == 0) val += MOD; --val; return *this; } mint operator ++ (int) { mint res = *this; ++*this; return res; } mint operator -- (int) { mint res = *this; --*this; return res; } friend istream& operator >> (istream &is, mint &x) { long long t; is >> t; x = mint(t); return is; } friend ostream& operator << (ostream &os, const mint &x) { return os << x.get(); } friend mint pow(const mint &r, long long n) { return r.pow(n); } friend mint inv(const mint &r) { return r.inv(); } }; typename MontgomeryModInt64::u64 MontgomeryModInt64::MOD, MontgomeryModInt64::INV_MOD, MontgomeryModInt64::T128; // Miller-Rabin bool MillerRabin(long long N, vector<long long> A) { using mint = MontgomeryModInt64; mint::set_mod(N); long long s = 0, d = N - 1; while (d % 2 == 0) { ++s; d >>= 1; } for (auto a : A) { if (N <= a) return true; mint x = mint(a).pow(d); if (x != 1) { long long t; for (t = 0; t < s; ++t) { if (x == N - 1) break; x *= x; } if (t == s) return false; } } return true; } bool is_prime(long long N) { if (N <= 1) return false; else if (N == 2) return true; else if (N % 2 == 0) return false; else if (N < 4759123141LL) return MillerRabin(N, {2, 7, 61}); else return MillerRabin(N, {2, 325, 9375, 28178, 450775, 9780504, 1795265022}); } // Pollard's Rho unsigned int xor_shift_rng() { static unsigned int tx = 123456789, ty=362436069, tz=521288629, tw=88675123; unsigned int tt = (tx^(tx<<11)); tx = ty, ty = tz, tz = tw; return ( tw=(tw^(tw>>19))^(tt^(tt>>8)) ); } long long pollard(long long N) { if (N % 2 == 0) return 2; if (is_prime(N)) return N; using mint = MontgomeryModInt64; mint::set_mod(N); long long step = 0; while (true) { mint r = xor_shift_rng(); // random r auto f = [&](mint x) -> mint { return x * x + r; }; mint x = ++step, y = f(x); while (true) { long long p = gcd((y - x).get(), N); if (p == 0 || p == N) break; if (p != 1) return p; x = f(x); y = f(f(y)); } } } vector<long long> prime_factorize(long long N) { if (N == 1) return {}; long long p = pollard(N); if (p == N) return {p}; vector<long long> left = prime_factorize(p); vector<long long> right = prime_factorize(N / p); left.insert(left.end(), right.begin(), right.end()); sort(left.begin(), left.end()); return left; } template<class T> struct Partition { vector<vector<T> > P; constexpr Partition(int MAX) noexcept : P(MAX, vector<T>(MAX, 0)) { for (int k = 0; k < MAX; ++k) P[0][k] = 1; for (int n = 1; n < MAX; ++n) { for (int k = 1; k < MAX; ++k) { P[n][k] = P[n][k-1] + (n-k >= 0 ? P[n-k][k] : 0); } } } constexpr T get(int n, int k) { if (n < 0 || k < 0) return 0; return P[n][k]; } }; int main() { cin.tie(0); ios::sync_with_stdio(false); ll n; cin >> n; auto res = prime_factorize(n); map<ll, ll> mp; foa(e, res) mp[e] ++; vector<ll> v; foa(e, mp) v.pb(e.second); ll ans = 0; Partition<ll> pt(60); for(ll i = 1; i < 60; i ++) { ll num = 1; foa(e, v) { num *= pt.get(e, i); } ll d = 1; foa(e, v) { d *= pt.get(e, i - 1); } ans += num - d; } cout << ans << endl; return 0; }