結果
問題 |
No.847 Divisors of Power
|
ユーザー |
|
提出日時 | 2019-07-23 08:39:04 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 1,180 bytes |
コンパイル時間 | 1,582 ms |
コンパイル使用メモリ | 171,800 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-07 02:03:09 |
合計ジャッジ時間 | 2,585 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 26 |
ソースコード
#include <bits/stdc++.h> #define rep(i, n) for(long long i = 0; i < (long long)(n); i++) using namespace std; using ll = long long; using P = pair<ll, ll>; // 素因数分解(first要素がfactで、second要素がその個数) vector<pair<ll, ll>> prime_factorize(ll n) { vector<pair<ll, ll>> res; for (ll p = 2; p * p <= n; ++p) { if (n % p != 0) continue; int num = 0; while (n % p == 0) { ++num; n /= p; } res.push_back(make_pair(p, num)); } if (n != 1) res.push_back(make_pair(n, 1)); return res; } vector<P> fact; int ans = 0; ll m; void dfs(int n, ll sum){ if(fact.size() == n) return; if(sum > m) return; dfs(n+1, sum); rep(i, fact[n].second){ sum *= fact[n].first; //cout << "s = " << sum << endl; if(sum > m) break; if(sum <= m) ans++; dfs(n+1, sum); } } int main(){ ll n, k; cin >> n >> k >> m; fact = prime_factorize(n); rep(i, fact.size()){ fact[i].second *= k; } /* for(auto p: fact){ cout << "fact: " << p.first << ", N: " << p.second << endl; } */ dfs(0, 1); cout << ans+1 << endl; }