結果
問題 | No.2318 Phys Bone Maker |
ユーザー | hliuser1 |
提出日時 | 2023-06-09 05:55:54 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,877 bytes |
コンパイル時間 | 3,039 ms |
コンパイル使用メモリ | 265,824 KB |
実行使用メモリ | 12,220 KB |
最終ジャッジ日時 | 2024-06-10 03:47:26 |
合計ジャッジ時間 | 11,993 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 7 ms
7,424 KB |
testcase_01 | AC | 8 ms
7,504 KB |
testcase_02 | AC | 601 ms
12,172 KB |
testcase_03 | AC | 18 ms
7,800 KB |
testcase_04 | RE | - |
testcase_05 | AC | 21 ms
7,808 KB |
testcase_06 | RE | - |
testcase_07 | AC | 10 ms
7,424 KB |
testcase_08 | AC | 21 ms
7,808 KB |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | AC | 28 ms
8,064 KB |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | AC | 30 ms
7,936 KB |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | AC | 17 ms
7,808 KB |
testcase_23 | RE | - |
testcase_24 | RE | - |
testcase_25 | RE | - |
testcase_26 | AC | 24 ms
7,936 KB |
testcase_27 | AC | 25 ms
7,936 KB |
testcase_28 | RE | - |
testcase_29 | RE | - |
testcase_30 | RE | - |
testcase_31 | RE | - |
testcase_32 | RE | - |
testcase_33 | AC | 8 ms
7,424 KB |
testcase_34 | AC | 24 ms
7,808 KB |
testcase_35 | AC | 78 ms
9,332 KB |
testcase_36 | AC | 303 ms
10,988 KB |
testcase_37 | AC | 291 ms
10,752 KB |
testcase_38 | AC | 315 ms
10,612 KB |
testcase_39 | AC | 455 ms
11,904 KB |
testcase_40 | AC | 453 ms
11,520 KB |
testcase_41 | AC | 505 ms
12,220 KB |
testcase_42 | AC | 511 ms
11,908 KB |
testcase_43 | AC | 29 ms
8,164 KB |
testcase_44 | AC | 85 ms
8,628 KB |
testcase_45 | AC | 78 ms
8,576 KB |
testcase_46 | AC | 522 ms
11,520 KB |
testcase_47 | AC | 29 ms
7,988 KB |
ソースコード
// https://yukicoder.me/problems/no/2318 // use the trick from Hossam & trainees. // compute list of all primes up to sqrt(N) // use repeated division to find any remaining "big" primes #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 = 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; ll primes[78498]; // list of all primes < 1e6 Map<ll, int> prime_factorize(ll x) { if (x < sieve::N) return prime.factors(x); Map<ll, int> mp; ll y = x; for (int p : primes) { while (y % p == 0) { y /= p; ++mp[p]; } if (y == 1) break; } if (y != 1) mp[y] = 1; return mp; } signed main() { ll N; cin >> N; for (int z{-1}, i{2}; i <= sqrt(N); ++i) if ( prime(i) ) primes[++z] = i; unordered_map<ll, ll> dp; // dp[x] = sum(dp[y]*Z forall y such that x%y==0) where Z is # of z s.t. lcm(y,z) = x dp[1] = 1; auto facts = factorize(N); int X = facts.size(); vector<Map<ll,int>> prime_facs(X); for (int i = 0; i < X; ++i) { ll f = facts[i]; prime_facs[i] = prime_factorize(f); } 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'; }