結果

問題 No.811 約数の個数の最大化
ユーザー aaaaaaiuaaaaaaiu
提出日時 2019-08-22 15:32:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 64 ms / 2,000 ms
コード長 702 bytes
コンパイル時間 1,986 ms
コンパイル使用メモリ 202,424 KB
実行使用メモリ 20,616 KB
最終ジャッジ日時 2024-04-20 16:36:22
合計ジャッジ時間 2,906 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 55 ms
18,996 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 6 ms
5,376 KB
testcase_07 AC 8 ms
5,760 KB
testcase_08 AC 28 ms
11,392 KB
testcase_09 AC 31 ms
12,032 KB
testcase_10 AC 19 ms
9,216 KB
testcase_11 AC 56 ms
18,944 KB
testcase_12 AC 16 ms
8,064 KB
testcase_13 AC 64 ms
20,616 KB
testcase_14 AC 64 ms
20,612 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