結果

問題 No.811 約数の個数の最大化
ユーザー pekempeypekempey
提出日時 2019-04-14 16:43:42
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 818 bytes
コンパイル時間 946 ms
コンパイル使用メモリ 84,688 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 07:48:21
合計ジャッジ時間 2,210 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 20 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 3 ms
4,348 KB
testcase_07 AC 4 ms
4,348 KB
testcase_08 AC 10 ms
4,348 KB
testcase_09 AC 7 ms
4,348 KB
testcase_10 AC 7 ms
4,348 KB
testcase_11 AC 9 ms
4,348 KB
testcase_12 AC 7 ms
4,348 KB
testcase_13 AC 11 ms
4,348 KB
testcase_14 AC 13 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0