結果
| 問題 |
No.811 約数の個数の最大化
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-04-14 00:44:16 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 12 ms / 2,000 ms |
| コード長 | 1,217 bytes |
| コンパイル時間 | 1,772 ms |
| コンパイル使用メモリ | 169,104 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-15 11:28:38 |
| 合計ジャッジ時間 | 2,287 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 12 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
vector<int> factorize(int N){
vector<int> fs;
for (int f = 2; f*f <= N; ++f){
while (N % f == 0){
fs.push_back(f);
N /= f;
}
}
if (N > 1) fs.push_back(N);
return fs;
}
bool has_K_common_factors(int n, int K, const vector<int> &fs){
for (auto f : fs){
if (n % f == 0){
n /= f;
--K;
}
}
return K <= 0;
}
int count_divisors(int n){
int n_div = 1;
for (int f = 2; f*f <= n; ++f){
int c = 1;
while (n % f == 0){
++c;
n /= f;
}
n_div *= c;
}
if (n > 1) n_div *= 2;
return n_div;
}
int solve(int N, int K){
int max_n_div = 1;
int ans = 1;
auto fs = factorize(N);
for (int i = 2; i < N; ++i){
if (has_K_common_factors(i, K, fs)){
int n_div = count_divisors(i);
if (n_div > max_n_div){
ans = i;
max_n_div = n_div;
}
}
}
return ans;
}
int main()
{
ios::sync_with_stdio(false);
cout.tie(0);
int N, K;
cin >> N >> K;
cout << solve(N, K) << endl;
return 0;
}