結果
問題 |
No.847 Divisors of Power
|
ユーザー |
|
提出日時 | 2020-02-28 01:27:22 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 7 ms / 2,000 ms |
コード長 | 962 bytes |
コンパイル時間 | 2,538 ms |
コンパイル使用メモリ | 195,424 KB |
最終ジャッジ日時 | 2025-01-09 02:24:36 |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 26 |
ソースコード
#include <bits/stdc++.h> #define int long long #define endl '\n' #define FOR(i, a, n) for (int i = (a); i < (n); ++i) #define REP(i, n) FOR(i, 0, n) using namespace std; // O(√n) time vector<pair<int, int>> prime_factor(int n) { vector<pair<int, int>> res; for (int i = 2; i * i <= n; i++) { int cnt = 0; while (n % i == 0) { n /= i; cnt++; } if (cnt) res.emplace_back(i, cnt); } if (n != 1) res.emplace_back(n, 1); return res; } int N, K, M; int dfs(int x, int idx, vector<pair<int, int>>& pf) { if (idx == pf.size()) return 1; int k = 1, res = 0; REP (i, pf[idx].second * K + 1) { res += dfs(x * k, idx + 1, pf); k *= pf[idx].first; if (x > M / k) break; } return res; } signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> N >> K >> M; auto pf = prime_factor(N); cout << dfs(1, 0, pf) << endl; }