結果
問題 |
No.811 約数の個数の最大化
|
ユーザー |
![]() |
提出日時 | 2019-04-12 22:28:56 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,844 bytes |
コンパイル時間 | 1,943 ms |
コンパイル使用メモリ | 181,524 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-14 20:14:44 |
合計ジャッジ時間 | 2,541 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 WA * 1 |
other | AC * 3 WA * 9 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll mod = 1e9 + 7; const ll inf = (1 << 30) - 1; const ll infll = (1LL << 61) - 1; vector<int> v; //map型 #include <map> template <typename T> map<T, int> prime_factor(T n) { map<T, int> res; for (T i = 2; i * i <= n; i++) { bool f = false; while (n % i == 0) { f = true; res[i]++; n /= i; } if (f == true) v.push_back(i); } if (n != 1) { res[n]++; //nは素数 v.push_back(n); } return res; } // 𝑂(𝑁*log(log 𝑁)) vector<int> eratosthenes(int N) { vector<int> res; vector<bool> prime(N + 1, 1); prime[0] = prime[1] = false; for (int i = 2; i * i <= N; ++i) { if (prime[i] == true) { for (int j = 2 * i; j <= N; j += i) { prime[j] = false; } } } for (int i = 0; i <= N; ++i) { if (prime[i] == true) res.push_back(i); } return res; } int n, k; int main() { cin >> n >> k; auto p = prime_factor(n); queue<int> que; int vs = v.size(); for (int i = 0; i < vs; i++) { que.push(v[i]); } map<int, int> mp; for (int i = 0; i < k; i++) { int j = que.front(); que.pop(); p[j]--; if (p[j] > 0) que.push(j); mp[j]++; } int ans = 1; for (auto e : v) { for (int i = 0; i < mp[e]; i++) { ans *= e; } } auto prime = eratosthenes(n); while (ans * 2 < n) { for (int i = 0; i < prime.size() && prime[i] * ans < n; i++) { ans *= prime[i]; mp[prime[i]]++; } } cout << ans << endl; }