結果

問題 No.811 約数の個数の最大化
ユーザー kk
提出日時 2020-07-03 20:23:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 18 ms / 2,000 ms
コード長 1,053 bytes
コンパイル時間 2,224 ms
コンパイル使用メモリ 205,604 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-15 03:41:12
合計ジャッジ時間 3,521 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for (int i=(int)(b); i<(int)(e); i++)
#define ALL(x) (x).begin(), (x).end()

const double PI = acos(-1);

map<long long, int> factorize(long long n) {
  map<long long, int> ret;
  
  for (long long i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ++ret[i];
      n /= i;
    }
  }
  
  if (n != 1)
    ret[n] = 1;
  
  return ret;
}

int divs[100000+1];

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  for (int i = 1; i <= 100000; i++) {
    for (int j = i; j <= 100000; j += i)
      divs[j]++;
  }
  
  int n, k;
  cin >> n >> k;

  auto fac = factorize(n);
  int ret = 0;
  for (int i = 1; i < n; i++) {
    int x = i;
    int cnt = 0;
    for (auto &pr: fac) {
      REP (j, pr.second) {
        if (x % pr.first == 0) {
          ++cnt;
          x /= pr.first;
        }
      }
    }
    if (cnt < k) continue;
    if (ret == 0 || divs[i] > divs[ret])
      ret = i;
  }
  cout << ret << endl;

  return 0;
}
0