結果

問題 No.811 約数の個数の最大化
ユーザー face4face4
提出日時 2019-04-12 21:44:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 1,088 bytes
コンパイル時間 769 ms
コンパイル使用メモリ 82,032 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-12 19:30:09
合計ジャッジ時間 1,894 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 51 ms
4,348 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 3 ms
4,348 KB
testcase_05 AC 3 ms
4,348 KB
testcase_06 AC 6 ms
4,348 KB
testcase_07 AC 8 ms
4,348 KB
testcase_08 AC 25 ms
4,348 KB
testcase_09 AC 27 ms
4,348 KB
testcase_10 AC 18 ms
4,348 KB
testcase_11 AC 52 ms
4,348 KB
testcase_12 AC 14 ms
4,348 KB
testcase_13 AC 58 ms
4,348 KB
testcase_14 AC 58 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<map>
using namespace std;
typedef long long ll;

int main(){
    bool nonp[100001] = {};
    vector<int> p;
    for(int i = 2; i < 100001; i++){
        if(nonp[i]) continue;
        p.push_back(i);
        for(int j = i+i; j < 100001; j += i)    nonp[j] = true;
    }

    int N, k;
    cin >> N >> k;
    int n = N;
    map<int, int> fact;
    for(int prime : p){
        while(n%prime == 0){
            n /= prime;
            fact[prime]++;
        }
    }
    if(n != 1)  fact[n]++;

    n = N;
    int ans = -1;
    ll score = 0;
    for(int i = 1; i < n; i++){
        map<int,int> use;
        int cp = i;
        for(int j = 2; j*j <= cp; j++){
            while(cp%j == 0)    cp /= j, use[j]++;
        }
        if(cp != 1) use[cp]++;
        int tmp = 0;
        ll tmps = 1;
        for(auto x : use){
            int add = min(x.second, fact[x.first]);
            tmp += add;
            tmps *= x.second+1;
        }
        if(tmp >= k && tmps > score)    ans = i, score = tmps;
    }
    cout << ans << endl;
    return 0;
}
0