結果
問題 | No.2318 Phys Bone Maker |
ユーザー |
👑 ![]() |
提出日時 | 2023-05-27 00:47:44 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,103 ms / 3,000 ms |
コード長 | 7,955 bytes |
コンパイル時間 | 3,010 ms |
コンパイル使用メモリ | 222,968 KB |
最終ジャッジ日時 | 2025-02-13 08:45:37 |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 45 |
ソースコード
#include <bits/stdc++.h>using namespace std;using ll = long long;#ifdef MY_DEBUG#define dbg(...) debug_out(__VA_ARGS__)#define dbgn(var) debug_out(#var, "=", var)#else#define dbg(...)#define dbgn(...)#endifvoid debug_out();template <class Head, class... Tail> void debug_out(Head, Tail...);template <class T> bool chmax(T&, const T&);template <class T> bool chmin(T&, const T&);template <class T> T pwr(T, ll);template <class T> T squ(T x) { return x * x; }ll fact(ll);ll comb(ll, ll);ll ctoll(char);char lltoc(ll);bool flg(ll b, ll i) { return ((b) >> (i)) & 1LL; } // flg(0b010, 1LL) -> trueconst ll LINF = (ll)1e18 + 7;const double EPS = 1e-9;const int MAX_DUBUG_SIZE = 10;#include <atcoder/math>#include <atcoder/modint>using namespace atcoder;// const int MOD = 1e9 + 7;// using mint = modint1000000007;const int MOD = 998244353;using mint = modint998244353;// using mint = modint; // main の最初で mint::setmod(/* 任意のMOD */);ostream& operator<<(ostream& os, const mint& N) { return os << N.val(); }// 計算量 O(√N)vector<ll> divisor(ll N) {vector<ll> res;for (ll i = 1; i * i <= N; ++i) {if (N % i == 0) {res.push_back(i);// 重複しないならば i の相方である N/i も pushif (N / i != i) res.push_back(N / i);}}// 小さい順に並び替えるsort(res.begin(), res.end());return res;}// 素因数分解 計算量O(√N)map<ll, ll> prime_factor(ll N) {map<ll, ll> res;for (ll i = 2; i * i <= N; i++) {while (N % i == 0) {res[i]++;N /= i;}}if (N != 1) { // N が素数の場合res[N] = 1;}return res;}vector<pair<ll, ll>> prime_factor_vector(ll N) {vector<pair<ll, ll>> res;for (ll i = 2; i * i <= N; i++) {ll cnt = 0;while (N % i == 0) {cnt++;N /= i;}if (cnt > 0) res.push_back({i, cnt});}if (N > 1) { // N が素数の場合res.push_back({N, 1});}return res;}void solve([[maybe_unused]] int test) {ll n;cin >> n;vector<ll> divs = divisor(n);auto pf_n = prime_factor(n);vector<pair<ll, vector<pair<ll, ll>>>> divs_pf;for (auto&& x : divs) {auto pf = prime_factor(x);vector<pair<ll, ll>> pf_x;for (auto&& [p, q] : pf_n) {pf_x.push_back({p, pf[p]});}divs_pf.push_back({x, pf_x});}ll sz = divs.size();vector<mint> dp(sz, 0);dp[0] = 1;for (ll i = 0; i < sz; i++) {auto [x, pf_x] = divs_pf[i];for (ll j = i + 1; j < sz; j++) {auto [y, pf_y] = divs_pf[j];if (y % x != 0) continue;mint tmp = dp[i];for (ll k = 0; k < pf_n.size(); k++) {if (pf_y[k].second == 0) continue;if (pf_x[k].second == pf_y[k].second) {tmp *= pf_y[k].second + 1;}}dp[j] += tmp;}}cout << dp[sz - 1] << "\n";}int main() {cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(12);int testcase_size = 1;// cin >> testcase_size;for (int _t = 0; _t < testcase_size; _t++) {solve(_t);}}/*-----------------------------------MY_FUNCTIONS------------------------------------ */template <class First, class Second> ostream& operator<<(ostream& os, const pair<First, Second>& pp) {return os << "{" << pp.first << "," << pp.second << "}";}template <class T> ostream& operator<<(ostream& os, const vector<T>& V) {if (V.empty()) return os << "[]";os << "[";for (ll i = 0; i < (ll)V.size(); i++) {os << V[i] << (i == int(V.size() - 1) ? "]" : ",");}return os;}template <class T> ostream& operator<<(ostream& os, const vector<vector<T>>& VV) {if (VV.empty()) return os << "[[]]";os << "[\n";for (auto&& V : VV) {os << V << "\n";}os << "]";return os;}template <class T> ostream& operator<<(ostream& os, const vector<vector<vector<T>>>& VVV) {if (VVV.empty()) return os << "[[[]]]";os << "["<< "\n";int cnt = 0;for (auto&& VV : VVV) {os << cnt++ << VV << "\n\n";}os << "]";return os;}template <class T> ostream& operator<<(ostream& os, const set<T>& SS) {if (SS.empty()) return os << "[]";os << "[";auto ii = SS.begin();for (; ii != SS.end(); ii++) os << *ii << (ii == prev(SS.end()) ? "]" : ",");return os;}template <class Key, class Tp> ostream& operator<<(ostream& os, const map<Key, Tp>& MM) {if (MM.empty()) return os << "[{:}]";os << "[";auto ii = MM.begin();for (; ii != MM.end(); ii++)os << "{" << ii->first << ":" << ii->second << "}" << (ii == prev(MM.end()) ? "]" : ",");return os;}void debug_out() { cerr << endl; }void debug_out_vl(vector<ll> V) {const int MAX_SIZE = min((int)V.size(), MAX_DUBUG_SIZE);cerr << "\033[33m";if (V.empty()) {cerr << "[]" << endl;return;}cerr << "[";for (int i = 0; i < MAX_SIZE; i++) {if (V[i] == LINF)cerr << "INF";elsecerr << V[i];if (i == (int)V.size() - 1)cerr << "]\n";else if (i == MAX_DUBUG_SIZE - 1)cerr << ",...\n";elsecerr << ",";}return;}void debug_out_vvl(vector<vector<ll>> VV) {cerr << "\033[33m";if (VV.empty()) {cerr << "[[]]" << endl;return;}cerr << "[\n";int MAX_ROW = min((int)VV.size(), MAX_DUBUG_SIZE);for (int i = 0; i < MAX_ROW; i++) {const int MAX_COLUMN = min((int)VV[i].size(), MAX_DUBUG_SIZE);if (VV[i].empty()) {cerr << "[]" << endl;continue;}cerr << "[";for (int j = 0; j < MAX_COLUMN; j++) {if (VV[i][j] == LINF)cerr << "INF";elsecerr << VV[i][j];if (j == (int)VV[i].size() - 1)cerr << "]\n";else if (j == MAX_DUBUG_SIZE - 1)cerr << ",...\n";elsecerr << ",";}if (i != (int)VV.size() - 1 and i == MAX_DUBUG_SIZE - 1) {cerr << ":\n:\033[m\n";return;}}cerr << "]\033[m\n";return;}template <class Head, class... Tail> void debug_out(Head H, Tail... T) {if constexpr (std::is_same_v<Head, vector<ll>>) {debug_out_vl(H);}else if constexpr (std::is_same_v<Head, vector<vector<ll>>>) {debug_out_vvl(H);}else {cerr << "\033[33m" << H << "\033[m ";}debug_out(T...);}template <class T> bool chmax(T& a, const T& b) {if (a < b) {a = b;return true;}return false;}template <class T> bool chmin(T& a, const T& b) {if (b < a) {a = b;return true;}return false;}template <class T> T pwr(T x, ll n) {T res = 1;for (int i = 0; i < n; i++) {res *= x;}return res;}ll fact(ll n) {ll res = 1;for (ll i = 1; i <= n; i++) res *= i;return res;}ll comb(ll n, ll r) { // comb(60, 30)までオーバーフローなしll res = 1;for (int i = 1; i <= r; i++) {res *= n--;res /= i;}return res;}ll ctoll(char c) {if (c < '0' or '9' < c) {cerr << "\n\033[33m ctoll に '0'~'9' 以外の文字が入りました.\033[m\n" << endl;}return ll(c - '0');}char lltoc(ll n) {if (n < 0 or 9 < n) {cerr << "\n\033[33m lltoc に 0 ~ 9 以外の数字が入りました.\033[m\n" << endl;}return char(n + '0');}