結果

問題 No.811 約数の個数の最大化
ユーザー MayimgMayimg
提出日時 2019-04-15 20:16:36
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 854 bytes
コンパイル時間 2,054 ms
コンパイル使用メモリ 204,308 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-22 06:45:58
合計ジャッジ時間 2,864 ms
ジャッジサーバーID
(参考情報)
judge10 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 15 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 3 ms
4,348 KB
testcase_08 AC 9 ms
4,348 KB
testcase_09 AC 10 ms
4,348 KB
testcase_10 AC 6 ms
4,348 KB
testcase_11 AC 13 ms
4,348 KB
testcase_12 AC 6 ms
4,348 KB
testcase_13 AC 25 ms
4,348 KB
testcase_14 AC 16 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
int cnt1(int x) {
  int res = 0;
  for (int i = 2; i * i <= x; i++) {
    while (x % i == 0) {
      res++;
      x /= i;
    }
  }
  return res + (x > 1);
}
int cnt2(int x) {
  vector<int> res;
  for (int i = 2; i * i <= x; i++) {
    int cnt = 0;
    while (x % i == 0) {
      cnt++;
      x /= i;
    }
    if (cnt) res.push_back(cnt);
  }
  if (x > 1) res.push_back(1);
  int ret = 1;
  for (int i : res) {
    ret *= (i + 1);
  }
  return ret;
}
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int n, k;
  cin >> n >> k;
  int cnt = 0;
  int ans = 0;
  for (int x = n - 1;  x >= 1; x--) {
    if (cnt1(__gcd(x, n)) >= k) {
      int tmp = cnt2(x);
      if (tmp >= cnt) {
        cnt = tmp;
        ans = x;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
0