結果

問題 No.811 約数の個数の最大化
ユーザー YamaKasaYamaKasa
提出日時 2019-06-27 12:49:11
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 15 ms / 2,000 ms
コード長 1,396 bytes
コンパイル時間 1,852 ms
コンパイル使用メモリ 168,388 KB
実行使用メモリ 4,544 KB
最終ジャッジ日時 2023-09-09 23:16:21
合計ジャッジ時間 3,066 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

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 gcd(int m, int n) {
  if (n == 0) return m;
  else return gcd(n, m % n);
}

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;

  for (int i = 2; i < N; i++) {
    for (int j = i; j < N; j += i) {
      dp[j]++;
    }
  }
  vector<int> v;
  int n = N;
  for (int i = 2; i <= m; i++) {
    while (n % i == 0) {
      v.push_back(i);
      n /= i;
    }
  }
  int dp2[N]{};
  for (int i = 2; i < N; i++) {
    dp2[i] = 1;
  }
  for (int i = 2; i * i < N; i++) {
    for (int j = 2; i * j < N; j++) {
      dp2[i * j] = dp2[i] + dp2[j];
    }
  }

  int ans = 1;
  int maxV = 0;
  for (int i = 1; i < N; i++) {
    int g = gcd(N, i);
    if (maxV < dp[i] && K <= dp2[g]) {
      maxV = dp[i];
      ans = i;
    }
  }

  cout << ans << "\n";
  return 0;
}
0