結果
| 問題 |
No.811 約数の個数の最大化
|
| コンテスト | |
| ユーザー |
a
|
| 提出日時 | 2019-04-13 13:03:33 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 26 ms / 2,000 ms |
| コード長 | 788 bytes |
| コンパイル時間 | 1,644 ms |
| コンパイル使用メモリ | 171,436 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-09-15 08:33:42 |
| 合計ジャッジ時間 | 2,226 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge6 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 12 |
ソースコード
#include "bits/stdc++.h"
using namespace std;
vector<pair<int, int>> factors(int x)
{
vector<pair<int, int>> ps;
for (int i = 2; i * i <= x; i++)
{
if (x % i) continue;
int cnt = 0;
while(x % i == 0)
{
cnt++;
x /= i;
}
ps.push_back({i, cnt});
}
if (x > 1) ps.push_back({x, 1});
return ps;
}
void solve()
{
int n, k;
cin >> n >> k;
int ans = 0, maxi = 0;
for (int x = 1; x < n; x++)
{
int g = __gcd(x, n);
auto gp = factors(g);
int cnt = 0;
for (auto p : gp)
{
cnt += p.second;
}
if (cnt < k) continue;
auto ps = factors(x);
int m = 1;
for (auto p : ps)
{
m *= p.second + 1;
}
if (m > maxi)
{
maxi = m;
ans = x;
}
}
cout << ans << endl;
}
int main()
{
solve();
//cout << "yui(*-v・)yui" << endl;
return 0;
}
a