結果

問題 No.811 約数の個数の最大化
ユーザー aaaaaaiuaaaaaaiu
提出日時 2019-08-22 15:32:48
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 74 ms / 2,000 ms
コード長 702 bytes
コンパイル時間 2,127 ms
コンパイル使用メモリ 207,088 KB
実行使用メモリ 20,636 KB
最終ジャッジ日時 2023-08-02 16:31:33
合計ジャッジ時間 3,388 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 64 ms
18,876 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 3 ms
4,380 KB
testcase_06 AC 6 ms
4,772 KB
testcase_07 AC 9 ms
5,592 KB
testcase_08 AC 31 ms
11,440 KB
testcase_09 AC 36 ms
11,980 KB
testcase_10 AC 22 ms
9,112 KB
testcase_11 AC 64 ms
18,956 KB
testcase_12 AC 18 ms
7,976 KB
testcase_13 AC 74 ms
20,636 KB
testcase_14 AC 70 ms
20,584 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    int n,k;
    cin>>n>>k;
    map<int,int> pf[n+1];
    for (int i=1;i<=n;i++) {
        int t=i;
        for (int j=2;j*j<=t;j++)
            while (t%j==0) {
                pf[i][j]++;
                t/=j;
            }
        if (t>1) pf[i][t]++;
    }
    int ans=0;
    int mx=0;
    for (int i=1;i<n;i++) {
        int g=gcd(i,n);
        int sum=0;
        for (auto p:pf[g]) sum+=p.second;
        if (sum<k) continue;
        int div=1;
        for (auto p:pf[i])
            div*=p.second+1;
        if (div>mx) {
            ans=i;
            mx=div;
        }
    }
    cout<<ans<<endl;
    return 0;
}
0