結果

問題 No.811 約数の個数の最大化
ユーザー yuji9511yuji9511
提出日時 2019-04-12 23:20:16
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,712 bytes
コンパイル時間 1,399 ms
コンパイル使用メモリ 158,684 KB
実行使用メモリ 4,480 KB
最終ジャッジ日時 2023-10-13 09:10:51
合計ジャッジ時間 2,196 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,352 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 WA -
testcase_09 AC 4 ms
4,352 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 31 ms
4,348 KB
testcase_14 AC 2 ms
4,352 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();
    // printa(dd, nn);
    // vector<ll> tmp = factor(75600);
    // printa(tmp, tmp.size());
    ll m = 1;
    map<ll,ll> mp;
    rep(i,0,nn) mp[dd[i]]++;
    ll cnt = 0;
    while(cnt < K){
        for(auto &e: mp){
            if(e.second > 0){
                m *= e.first;
                mp[e.first]--;
                cnt++;
                if(cnt >= K) break;
            }
        }
    }
    ll max_val = 0, max_pos = 0;
    for(int t = m; t < N; t += m){
        vector<ll> k = factor(t);
        map<ll,ll> mp2;
        rep(i,0,k.size()) mp2[k[i]]++;
        ll v = 1;
        for(auto &e: mp2) v *= (e.second) + 1;
        if(max_val < v){
            max_val = v;
            max_pos = t;
        }
    }
    print(max_pos);
    // for(auto &e: mp){
    //     print(e.first);
    // }




}
0