結果
| 問題 |
No.811 約数の個数の最大化
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-08-22 15:32:48 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 77 ms / 2,000 ms |
| コード長 | 702 bytes |
| コンパイル時間 | 2,266 ms |
| コンパイル使用メモリ | 200,824 KB |
| 最終ジャッジ日時 | 2025-01-07 14:37:36 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 12 |
ソースコード
#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;
}