結果
問題 | No.811 約数の個数の最大化 |
ユーザー |
|
提出日時 | 2019-04-14 00:37:11 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 305 ms / 2,000 ms |
コード長 | 1,154 bytes |
コンパイル時間 | 1,744 ms |
コンパイル使用メモリ | 168,660 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-15 11:25:52 |
合計ジャッジ時間 | 2,652 ms |
ジャッジサーバーID (参考情報) |
judge6 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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 <= N; ++f){ while (N % f == 0){ fs.push_back(f); N /= f; } } 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 <= n; ++f){ int c = 1; while (n % f == 0){ ++c; n /= f; } n_div *= c; } 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; }