結果

問題 No.811 約数の個数の最大化
ユーザー polylogKpolylogK
提出日時 2019-04-12 21:51:43
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 47 ms / 2,000 ms
コード長 1,044 bytes
コンパイル時間 538 ms
コンパイル使用メモリ 54,592 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-12 19:49:17
合計ジャッジ時間 1,414 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <stdio.h>
#include <vector>
#include <functional>
#include <algorithm>
#include <utility>

int main() {
    int n, k; scanf("%d%d", &n, &k);

    std::function<int (int)> countDivisor = [](int x) {
        int count = 0;
        for(int i = 1; i * i <= x; i++) {
            if(x % i) continue;
            count += 2;
            if(i * i == x) count--;
        }
        return count;
    };

    std::function<int (int, int)> countCommonFactor = [](int x, int y) {
        int g = std::__gcd(x, y);

        int count = 0;
        for(int i = 2; i * i <= g; i++) {
            if(g % i) continue;
            while(g % i == 0) {
                g /= i;
                count++;
            }
        }
        if(g != 1) count++;
        return count;
    };

    int ans = 0, ma = 0;
    for(int i = 1; i < n; i++) {
        if(countCommonFactor(i, n) < k) continue;
        int latte = countDivisor(i);
        if(latte > ma) {
            ma = latte;
            ans = i;
        }
    }
    printf("%d\n", ans);
    return 0;
}
0