結果
問題 | No.2318 Phys Bone Maker |
ユーザー | hliuser1 |
提出日時 | 2023-06-09 05:23:36 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 661 ms / 3,000 ms |
コード長 | 2,741 bytes |
コンパイル時間 | 2,721 ms |
コンパイル使用メモリ | 265,088 KB |
実行使用メモリ | 11,144 KB |
最終ジャッジ日時 | 2024-06-10 03:34:23 |
合計ジャッジ時間 | 9,189 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 9 ms
7,976 KB |
testcase_01 | AC | 9 ms
7,984 KB |
testcase_02 | AC | 661 ms
11,144 KB |
testcase_03 | AC | 17 ms
8,028 KB |
testcase_04 | AC | 26 ms
8,132 KB |
testcase_05 | AC | 20 ms
7,972 KB |
testcase_06 | AC | 22 ms
8,020 KB |
testcase_07 | AC | 11 ms
8,052 KB |
testcase_08 | AC | 21 ms
8,036 KB |
testcase_09 | AC | 24 ms
8,008 KB |
testcase_10 | AC | 33 ms
7,980 KB |
testcase_11 | AC | 36 ms
7,956 KB |
testcase_12 | AC | 50 ms
7,996 KB |
testcase_13 | AC | 27 ms
8,016 KB |
testcase_14 | AC | 28 ms
7,948 KB |
testcase_15 | AC | 28 ms
8,004 KB |
testcase_16 | AC | 22 ms
7,992 KB |
testcase_17 | AC | 28 ms
8,096 KB |
testcase_18 | AC | 55 ms
8,000 KB |
testcase_19 | AC | 20 ms
7,952 KB |
testcase_20 | AC | 26 ms
7,968 KB |
testcase_21 | AC | 23 ms
8,004 KB |
testcase_22 | AC | 19 ms
8,120 KB |
testcase_23 | AC | 20 ms
8,144 KB |
testcase_24 | AC | 30 ms
8,028 KB |
testcase_25 | AC | 29 ms
8,136 KB |
testcase_26 | AC | 23 ms
8,000 KB |
testcase_27 | AC | 24 ms
8,008 KB |
testcase_28 | AC | 22 ms
8,136 KB |
testcase_29 | AC | 18 ms
8,004 KB |
testcase_30 | AC | 17 ms
8,004 KB |
testcase_31 | AC | 39 ms
8,016 KB |
testcase_32 | AC | 26 ms
7,960 KB |
testcase_33 | AC | 9 ms
7,940 KB |
testcase_34 | AC | 22 ms
8,088 KB |
testcase_35 | AC | 82 ms
9,288 KB |
testcase_36 | AC | 320 ms
10,352 KB |
testcase_37 | AC | 315 ms
10,080 KB |
testcase_38 | AC | 323 ms
9,932 KB |
testcase_39 | AC | 483 ms
10,816 KB |
testcase_40 | AC | 476 ms
10,612 KB |
testcase_41 | AC | 553 ms
10,976 KB |
testcase_42 | AC | 549 ms
10,976 KB |
testcase_43 | AC | 27 ms
8,000 KB |
testcase_44 | AC | 92 ms
8,636 KB |
testcase_45 | AC | 88 ms
8,608 KB |
testcase_46 | AC | 560 ms
10,688 KB |
testcase_47 | AC | 28 ms
8,096 KB |
ソースコード
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC target("sse4") using namespace std; using ll = long long; static constexpr ll Q = 998244353; template <typename K, typename V> using Map = unordered_map<K, V>; template <typename Int> vector<Int> factorize(Int n, Int i=1) { vector<Int> f; f.reserve( sqrt(n) ); for (; i*i < n; ++i) if (n % i == 0) f.push_back(i); i -= (i - (n / i) == 1); for (; i >= 1; i--) if (n % i == 0) f.push_back(n/i); return f; } struct sieve { static constexpr size_t N = 1000001; int spf[N] = {}; sieve() { spf[0] = spf[1] = -1; for (int i = 3; i <= N; i += 2) spf[i] = i; for (int i = 2; i <= N; i += 2) spf[i] = 2; // avoid lots of % later for (int i = 3; i*i <= N; i += 2) { if (spf[i] != i) continue; for (int j = i*i; j <= N; j += i) if (spf[j] == j) spf[j] = i; } } inline bool operator()(int n) { return spf[n] == n; } template <class Int> inline Map<Int, int> factors(Int n) { Map<Int, int> mp; while (n != 1) { int p = spf[n]; while (n % p == 0) { ++mp[p]; n /= p; } } return mp; } } prime; int z{-1}; ll primes[78498]; signed main() { ll N; cin >> N; unordered_map<ll, ll> dp; dp[1] = 1; auto facts = factorize(N); int X = facts.size(); // dp[x] = sum(dp[y]*Z forall y such that x%y==0) where Z is # of z s.t. lcm(y,z) = x for (int i = 2; i < sieve::N; ++i) if (prime(i)) primes[++z] = i; vector<Map<ll,int>> prime_facs(X); for (int i = 0; i < X; ++i) { ll x = facts[i]; if (x < sieve::N) prime_facs[i] = prime.factors(x); else { ll y = x; for (int j = 0; j < 78498; ++j) { int p = primes[j]; while (y % p == 0) { y /= p; ++prime_facs[i][p]; } if (y == 1) break; } if (y != 1) prime_facs[i][y] = 1; } } for (int i = 1; i < X; ++i) { ll x = facts[i]; auto& pfx = prime_facs[i]; for (int j = 0; j < i; ++j) { ll y = facts[j]; if (x % y != 0) continue; ll ways = dp[y]; // # of z where lcm(y,z) = x auto& pfy = prime_facs[j]; for (auto [p, cnt] : pfx) if (pfy[p] == cnt) ways = ways * (cnt+1) % Q; dp[x] = (dp[x]+ways) % Q; } } cout << dp[N] << '\n'; }