結果

問題 No.811 約数の個数の最大化
ユーザー yuji9511yuji9511
提出日時 2019-04-12 23:26:55
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 122 ms / 2,000 ms
コード長 1,422 bytes
コンパイル時間 1,895 ms
コンパイル使用メモリ 158,348 KB
実行使用メモリ 4,376 KB
最終ジャッジ日時 2023-10-13 09:12:12
合計ジャッジ時間 3,011 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;

inline vector<ll> factor(ll M){ //素因数分解
    vector<ll> dd;
    if(M == 1){
        dd.push_back(1);
        return dd;
    }
    for(ll i = 2; i*i <= M; i++){
        while(M % i == 0){
            dd.push_back(i);
            M /= i;
        }
    }
    if(M != 1) dd.push_back(M);
    sort(dd.begin(), dd.end());
    return dd;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,K;
    cin >> N >> K;
    vector<ll> dd = factor(N);
    ll nn = dd.size();
    map<ll,ll> mp;
    rep(i,0,nn) mp[dd[i]]++;
    ll ans = 0, max_val = 0;
    rep(t,1,N){
        vector<ll> tt = factor(t);
        map<ll,ll> mp2;
        rep(i,0,tt.size()) mp2[tt[i]]++;
        ll k = 0;
        for(auto &e: mp2){
            k += min(e.second, mp[e.first]);
        }
        if(k < K) continue;
        ll v = 1;
        for(auto &e: mp2){
            v *= e.second + 1;
        }
        if(max_val < v){
            max_val = v;
            ans = t;
        }
    }
    print(ans);




}
0