結果

問題 No.811 約数の個数の最大化
ユーザー treeonetreeone
提出日時 2019-04-12 21:29:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 114 ms / 2,000 ms
コード長 950 bytes
コンパイル時間 2,521 ms
コンパイル使用メモリ 206,344 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-12 18:49:08
合計ジャッジ時間 3,345 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

map<int, int> mp;

map<int, int> prime_factor(int n){
    map<int, int> res;
    for(int i = 2; i * i <= n; i++){
        while(n % i == 0){
            ++res[i];
            n /= i;
        }
    }
    if(n != 1) res[n]++;
    return res;
}

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    int MAX = 0, ans = 0;
    mp = prime_factor(n);
    for(int i = 2; i < n; i++){
        map<int, int> mp2 = prime_factor(i);
        int tmp = 0;
        int sum = 1;
        for(auto j : mp2){
            tmp += min(mp[j.first], j.second);
            sum *= (j.second + 1);
        }
        if(tmp >= k && MAX < sum){
            MAX = sum;
            ans = i;
        }
    }
    cout << ans << endl;
}
0