結果
問題 | No.811 約数の個数の最大化 |
ユーザー |
|
提出日時 | 2019-04-14 16:43:42 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 20 ms / 2,000 ms |
コード長 | 818 bytes |
コンパイル時間 | 965 ms |
コンパイル使用メモリ | 85,084 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-19 04:06:03 |
合計ジャッジ時間 | 1,671 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 12 |
ソースコード
#include <iostream>#include <algorithm>#include <vector>#include <string>#include <map>using namespace std;map<int, int> f(int n) {map<int, int> res;for (int i = 2; i <= n; i++) {while (n % i == 0) {res[i]++;n /= i;}}return res;}int common(int n, map<int, int> mp) {int res = 0;for (auto e : mp) {int c = 0;while (n % e.first == 0) {n /= e.first;c++;}res += min(c, e.second);}return res;}int main() {int N, K;cin >> N >> K;vector<int> d(N);for (int i = 1; i < N; i++) {for (int j = i; j < N; j += i) {d[j]++;}}auto mp = f(N);pair<int, int> ans;for (int i = 1; i < N; i++) {if (common(i, mp) >= K) {ans = max(ans, {d[i], -i});}}cout << -ans.second << endl;}