結果

問題 No.811 約数の個数の最大化
ユーザー kappybarkappybar
提出日時 2020-04-10 15:48:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 116 ms / 2,000 ms
コード長 1,073 bytes
コンパイル時間 1,982 ms
コンパイル使用メモリ 171,832 KB
実行使用メモリ 4,376 KB
最終ジャッジ日時 2023-10-13 06:20:50
合計ジャッジ時間 3,560 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll =  long long ;
using P = pair<ll,ll> ;
const ll INF = 1e18;
const int MOD = 1000000007;

map<ll,ll> getPrimes_(ll x){
        map<ll,ll> res;
        for(ll i = 2; i * i <= x;i++){
                if(x%i ==0){
                        res[i] = 0;
                        while(x%i ==0) x /= i,res[i]++;
                }
        }
        if( x > 1) res[x] = 1;
        return res;
}

ll cnt_div(map<ll,ll> p){
    ll res = 1;
    for(auto k:p){
        res *= k.second + 1;
    }
    return res;
}

int main(){
    ll n;
    int k;
    cin >> n >> k;
    ll cnt_max = 0;
    ll ans = -1;
    map<ll,ll> n_prime = getPrimes_(n);
    for(int i=1;i<n;i++){
        map<ll,ll> i_prime = getPrimes_(i);
        int res = 0;
        for(auto p:i_prime){
            res += min(p.second,n_prime[p.first]);
        }
        if(res >= k){
            ll cnt = cnt_div(i_prime);
            if(cnt_max < cnt ) ans = i,cnt_max = cnt;
        }
    }
    cout << ans << endl;
    return 0;
}
0