結果

問題 No.811 約数の個数の最大化
ユーザー hipopohipopo
提出日時 2020-01-22 19:19:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 1,676 bytes
コンパイル時間 1,768 ms
コンパイル使用メモリ 111,408 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-22 21:54:14
合計ジャッジ時間 2,892 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 29 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 4 ms
4,380 KB
testcase_07 AC 5 ms
4,376 KB
testcase_08 AC 14 ms
4,376 KB
testcase_09 AC 17 ms
4,376 KB
testcase_10 AC 10 ms
4,376 KB
testcase_11 AC 24 ms
4,376 KB
testcase_12 AC 11 ms
4,376 KB
testcase_13 AC 26 ms
4,376 KB
testcase_14 AC 25 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;

using ll = long long;
using P = pair<int, int>;

const long long MOD = 1e9+7;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int divide[100000];
vector<int> sieve(int n) {
    for (int i = 0; i < n + 1; i++) divide[i] = 1;
    vector<int> is_prime(n + 1, true);
    for (int i = 2; i <= n; i++) {
        if (!is_prime.at(i)) continue;
        
        is_prime.at(i) = true;
        divide[i] = i;
        for (int j = i + i; j <= n; j += i) {
            is_prime.at(j) = false;
            divide[j] = i;
        }
    }
    vector<int> res;
    for (int i = 2; i <= n; i++) if (is_prime.at(i)) res.push_back(i);
    return res;
}

map<int, int> prime_factor(int n) {
    map<int, int> res;
    while (1 < n) {
        res[divide[n]]++;
        n /= divide[n];
    }
    return res;
}

int main() {
    int n, k;
    cin >> n >> k;
    sieve(n);
    
    int max_div = 0;
    int ans = -1;
    auto nps = prime_factor(n);
    for (int i = 1; i < n; i++) {
        auto ps = prime_factor(i);
        int common_prime = 0;
        for (auto np: nps) common_prime += min(ps[np.first], np.second);
        //cout << i << " " << common_prime << endl;
        if (common_prime < k) continue;

        int d = 1;
        for (auto p: ps) d *= (p.second + 1);
        if (max_div < d) {
            max_div = d;
            ans = i;
        }
    }
    cout << ans << endl;
}
0