結果
問題 | No.2798 Multiple Chain |
ユーザー | shobonvip |
提出日時 | 2024-06-25 23:25:43 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 107 ms / 2,000 ms |
コード長 | 5,134 bytes |
コンパイル時間 | 2,746 ms |
コンパイル使用メモリ | 220,800 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-25 23:25:51 |
合計ジャッジ時間 | 4,961 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 9 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 9 ms
5,376 KB |
testcase_06 | AC | 5 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 1 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 2 ms
5,376 KB |
testcase_11 | AC | 2 ms
5,376 KB |
testcase_12 | AC | 1 ms
5,376 KB |
testcase_13 | AC | 2 ms
5,376 KB |
testcase_14 | AC | 2 ms
5,376 KB |
testcase_15 | AC | 91 ms
5,376 KB |
testcase_16 | AC | 97 ms
5,376 KB |
testcase_17 | AC | 101 ms
5,376 KB |
testcase_18 | AC | 102 ms
5,376 KB |
testcase_19 | AC | 107 ms
5,376 KB |
testcase_20 | AC | 2 ms
5,376 KB |
testcase_21 | AC | 2 ms
5,376 KB |
testcase_22 | AC | 2 ms
5,376 KB |
testcase_23 | AC | 2 ms
5,376 KB |
testcase_24 | AC | 2 ms
5,376 KB |
testcase_25 | AC | 5 ms
5,376 KB |
testcase_26 | AC | 2 ms
5,376 KB |
testcase_27 | AC | 3 ms
5,376 KB |
testcase_28 | AC | 2 ms
5,376 KB |
testcase_29 | AC | 2 ms
5,376 KB |
testcase_30 | AC | 2 ms
5,376 KB |
testcase_31 | AC | 2 ms
5,376 KB |
testcase_32 | AC | 2 ms
5,376 KB |
testcase_33 | AC | 2 ms
5,376 KB |
testcase_34 | AC | 2 ms
5,376 KB |
testcase_35 | AC | 2 ms
5,376 KB |
testcase_36 | AC | 2 ms
5,376 KB |
testcase_37 | AC | 2 ms
5,376 KB |
testcase_38 | AC | 2 ms
5,376 KB |
testcase_39 | AC | 2 ms
5,376 KB |
testcase_40 | AC | 7 ms
5,376 KB |
testcase_41 | AC | 23 ms
5,376 KB |
testcase_42 | AC | 44 ms
5,376 KB |
testcase_43 | AC | 24 ms
5,376 KB |
testcase_44 | AC | 11 ms
5,376 KB |
testcase_45 | AC | 2 ms
5,376 KB |
testcase_46 | AC | 2 ms
5,376 KB |
testcase_47 | AC | 2 ms
5,376 KB |
testcase_48 | AC | 2 ms
5,376 KB |
testcase_49 | AC | 2 ms
5,376 KB |
testcase_50 | AC | 2 ms
5,376 KB |
testcase_51 | AC | 2 ms
5,376 KB |
testcase_52 | AC | 2 ms
5,376 KB |
testcase_53 | AC | 1 ms
5,376 KB |
ソースコード
#include<bits/stdc++.h> using namespace std; typedef long long ll; // Fast Factorization // https://judge.yosupo.jp/submission/38126 // !!! CHANGED THE PRIMARY TEST !!! typedef unsigned int uint; struct Mint { uint64_t n; static uint64_t mod, inv, r2; Mint() : n(0) { } Mint(const uint64_t &x) : n(init(x)) { } static uint64_t init(const uint64_t &w) { return reduce(__uint128_t(w) * r2); } static void set_mod(const uint64_t &m) { mod = inv = m; for(int i = 0; i < 5; i++) inv *= 2 - inv * m; r2 = -__uint128_t(m) % m; } static uint64_t reduce(const __uint128_t &x) { uint64_t y = uint64_t(x >> 64) - uint64_t((__uint128_t(uint64_t(x) * inv) * mod) >> 64); return int64_t(y) < 0 ? y + mod : y; } Mint& operator+= (const Mint &x) { n += x.n - mod; if(int64_t(n) < 0) n += mod; return *this; } Mint& operator+ (const Mint &x) const { return Mint(*this) += x; } Mint& operator*= (const Mint &x) { n = reduce(__uint128_t(n) * x.n); return *this; } Mint& operator* (const Mint &x) const { return Mint(*this) *= x; } uint64_t val() const { return reduce(n); } }; uint64_t Mint::mod, Mint::inv, Mint::r2; bool suspect(const uint64_t &a, const uint64_t &s, uint64_t d, const uint64_t &n) { if(Mint::mod != n) Mint::set_mod(n); Mint x(1), xx(a), o(x), m(n - 1); while(d > 0) { if(d & 1) x *= xx; xx *= xx; d >>= 1; } if(x.n == o.n) return true; for(uint r = 0; r < s; r++) { if(x.n == m.n) return true; x *= x; } return false; } bool is_prime(const uint64_t &n) { if(n <= 1 || (n > 2 && (~n & 1))) return false; uint64_t d = n - 1, s = 0; while(~d & 1) s++, d >>= 1; static const uint64_t a_big[] = {2, 325, 9375, 28178, 450775, 9780504, 1795265022}; static const uint64_t a_smo[] = {2, 7, 61}; if(n < 4759123141LL) { for(auto &&p : a_smo) { if(p >= n) break; if(!suspect(p, s, d, n)) return false; } } else { for(auto &&p : a_big) { if(p >= n) break; if(!suspect(p, s, d, n)) return false; } } return true; } uint64_t rho_pollard(const uint64_t &n) { if(~n & 1) return 2u; static random_device rng; uniform_int_distribution<uint64_t> rr(1, n - 1); if(Mint::mod != n) Mint::set_mod(n); for(;;) { uint64_t c_ = rr(rng), g = 1, r = 1, m = 500; Mint y(rr(rng)), xx(0), c(c_), ys(0), q(1); while(g == 1) { xx.n = y.n; for(uint i = 1; i <= r; i++) y *= y, y += c; uint64_t k = 0; g = 1; while(k < r && g == 1) { for(uint i = 1; i <= (m > (r - k) ? (r - k) : m); i++) { ys.n = y.n; y *= y; y += c; uint64_t xxx = xx.val(), yyy = y.val(); q *= Mint(xxx > yyy ? xxx - yyy : yyy - xxx); } g = __gcd<uint64_t>(q.val(), n); k += m; } r *= 2; } if(g == n) g = 1; while(g == 1) { ys *= ys; ys += c; uint64_t xxx = xx.val(), yyy = ys.val(); g = __gcd<uint64_t>(xxx > yyy ? xxx - yyy : yyy - xxx, n); } if(g != n && is_prime(g)) return g; } assert(69 == 420); } template <typename T> vector<T> inter_factor(const T &n) { if(n < 2) return { }; if(is_prime(n)) return {n}; T d = rho_pollard(static_cast<uint64_t>(n)); vector<T> l = inter_factor(d), r = inter_factor(n / d); l.insert(l.end(), r.begin(), r.end()); return l; } template <typename T> vector<T> factor(T n) { vector<T> f1; for(uint i = 2; i < 100; i += (i & 1) + 1) while(n % i == 0) f1.push_back(i), n /= i; vector<T> f2 = inter_factor(n); f1.insert(f1.end(), f2.begin(), f2.end()); sort(f1.begin(), f1.end()); return f1; } template <typename T> vector<vector<T>> makediv(T n) { vector<T> pf = factor(n); vector<pair<T,int>> cmp; assert(n >= 2); T memo = pf[0]; int tmp = 0; for (int i=0; i<(int)pf.size(); i++){ if (memo == pf[i]){ tmp++; }else{ cmp.push_back(pair(memo, tmp)); memo = pf[i]; tmp = 1; } } cmp.push_back(pair(memo, tmp)); vector<vector<T>> ret(61,vector<T>(0)); vector<int> tar(61); auto calc = [&](auto self, T i, int s, int r, bool use) -> void { if (use){ if (r >= 1){ for (int j=1; j<=60; j++){ if (r % j != 0) tar[j]++; } } for (int j=0; j<61; j++){ if (tar[j] >= 1) continue; ret[j].push_back(i); } if (r >= 1){ for (int j=1; j<=60; j++){ if (r % j != 0) tar[j]--; } } } if (s >= (int)cmp.size()) return; if (r + 1 <= cmp[s].second){ self(self, i * cmp[s].first, s, r + 1, 1); } if (r >= 1){ for (int j=1; j<=60; j++){ if (r % j != 0) tar[j]++; } } self(self, i, s + 1, 0, 0); if (r >= 1){ for (int j=1; j<=60; j++){ if (r % j != 0) tar[j]--; } } return; }; calc(calc, 1, 0, 0, 1); for (int i=0; i<=60; i++){ sort(ret[i].begin(), ret[i].end()); } return ret; } int main(){ ll n; cin >> n; vector<vector<ll>> d = makediv(n); auto calc = [&](auto self, ll i, int weight, bool start) -> ll { if (n % i != 0) return 0; if (weight == 1){ return 1LL; } ll ret = 0; for (ll x: d[weight]){ if ((__int128)i * x > n) break; if (start && x == 1) continue; ret += self(self, i * x, weight - 1, false); } return ret; }; ll ans = 0; for (int x=1; x<61; x++){ ans += calc(calc, 1LL, x, true); } cout << ans << '\n'; }