結果

問題 No.811 約数の個数の最大化
ユーザー YamaKasaYamaKasa
提出日時 2019-06-26 23:29:05
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,400 bytes
コンパイル時間 1,513 ms
コンパイル使用メモリ 167,964 KB
実行使用メモリ 8,592 KB
最終ジャッジ日時 2023-09-08 13:40:49
合計ジャッジ時間 13,712 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 3 ms
4,376 KB
testcase_02 TLE -
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 6 ms
4,380 KB
testcase_06 AC 38 ms
4,376 KB
testcase_07 AC 72 ms
4,376 KB
testcase_08 AC 817 ms
4,380 KB
testcase_09 AC 901 ms
4,376 KB
testcase_10 AC 439 ms
4,376 KB
testcase_11 TLE -
testcase_12 AC 295 ms
4,376 KB
testcase_13 TLE -
testcase_14 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
static const int MAX = 100001;
bool isPrime[MAX];

void aryPrime() {
  for (int i = 0; i < MAX; i++) {
    isPrime[i] = true;
  }
  isPrime[0] = false;
  isPrime[1] = false;
  int n = sqrt(MAX);
  for (int i = 2; i <= n; i++) {
    if (!isPrime[i]) continue;
    for (int j = i * 2; j < MAX; j += i) {
      isPrime[j] = false;
    }
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, K;
  cin >> N >> K;
  
  int m = sqrt(N);
  vector<int> p;
  aryPrime();
  for (int i = 2; i < N; i++) {
    if (isPrime[i]) {
      p.push_back(i);
    }
  }
  int dp[N];
  for (int i = 0; i < N; i++) {
    dp[i] = 1;
  }
  vector<int> s;
  for (int i = 2; i <= m; i++) {
    int t = N;
    if (t % i == 0) {
      s.push_back(i);
      while (t % i == 0) {
        t /= i;
      }
    }
  }
  for (int i = 1; i < N; i++) {
    int t = i;
    for (int j : p) {
      int cnt = 0;
      while (t % j == 0) {
        t /= j;
        cnt++;
      }
      dp[i] *= (cnt + 1);
    }
  }
  int g = 0;
  int ans = 0;
  for (int i = 1; i < N; i++) {
    int cnt = 0;
    int t = i;
    int n = N;
    for (int j : s) {
      while (t % j == 0 && n % j == 0) {
        t /= j;
        n /= j;
        cnt++;
      }
    }
    if (cnt >= K && g < dp[i]) {
      g = dp[i];
      ans = i;
    }
  }
  cout << ans << "\n";
  return 0;
}
0