結果

問題 No.811 約数の個数の最大化
ユーザー algon_320algon_320
提出日時 2019-04-12 22:02:37
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 116 ms / 2,000 ms
コード長 1,082 bytes
コンパイル時間 1,584 ms
コンパイル使用メモリ 170,644 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-12 20:24:52
合計ジャッジ時間 2,996 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 100 ms
4,352 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 3 ms
4,352 KB
testcase_06 AC 7 ms
4,348 KB
testcase_07 AC 10 ms
4,352 KB
testcase_08 AC 46 ms
4,348 KB
testcase_09 AC 47 ms
4,348 KB
testcase_10 AC 30 ms
4,348 KB
testcase_11 AC 99 ms
4,352 KB
testcase_12 AC 23 ms
4,348 KB
testcase_13 AC 114 ms
4,348 KB
testcase_14 AC 116 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
template <class T>
bool chmax(T &a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, const T& b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

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

signed main() {
    int N, K;
    cin >> N >> K;
    int ans = 0;
    int cnt = 0;
    auto F = factorize(N);
    rep(i, 1, N) {
        auto f = factorize(i);
        int tmp = 1;
        int tmp2 = 0;
        for (auto p : f) {
            tmp *= p.second + 1;
            tmp2 += min(F[p.first], p.second);
        }
        if (tmp2 < K) continue;
        if (chmax(cnt, tmp)) {
            ans = i;
        }
    }
    cout << ans << endl;
}
0