結果

問題 No.811 約数の個数の最大化
ユーザー Mayimg
提出日時 2019-04-15 20:16:36
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 854 bytes
コンパイル時間 2,185 ms
コンパイル使用メモリ 196,384 KB
最終ジャッジ日時 2025-01-07 02:14:31
ジャッジサーバーID
(参考情報)
judge3 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

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