結果
問題 | No.811 約数の個数の最大化 |
ユーザー | xuzijian629 |
提出日時 | 2019-04-13 00:55:10 |
言語 | C++17 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 42 ms / 2,000 ms |
コード長 | 883 bytes |
コンパイル時間 | 2,083 ms |
コンパイル使用メモリ | 205,764 KB |
実行使用メモリ | 4,352 KB |
最終ジャッジ日時 | 2023-10-13 09:25:10 |
合計ジャッジ時間 | 3,084 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge15 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,352 KB |
testcase_01 | AC | 2 ms
4,352 KB |
testcase_02 | AC | 14 ms
4,352 KB |
testcase_03 | AC | 1 ms
4,348 KB |
testcase_04 | AC | 1 ms
4,352 KB |
testcase_05 | AC | 2 ms
4,348 KB |
testcase_06 | AC | 2 ms
4,352 KB |
testcase_07 | AC | 3 ms
4,348 KB |
testcase_08 | AC | 7 ms
4,348 KB |
testcase_09 | AC | 11 ms
4,352 KB |
testcase_10 | AC | 6 ms
4,348 KB |
testcase_11 | AC | 12 ms
4,348 KB |
testcase_12 | AC | 4 ms
4,348 KB |
testcase_13 | AC | 42 ms
4,348 KB |
testcase_14 | AC | 14 ms
4,348 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; int cnt(int a, int b) { int g = __gcd(a, b); int ret = 0; for (int i = 2; i * i <= g; i++) { while (g % i == 0) { ret++; g /= i; } } if (g > 1) { ret++; } return ret; } int main() { int n, k; cin >> n >> k; vector<pair<int, int>> ans; for (int i = 2; i < n; i++) { if (cnt(i, n) >= k) { int num = 0; for (int j = 1; j * j <= i; j++) { if (i % j == 0) { num++; if (i / j != j) num++; } } ans.emplace_back(i, num); } } sort(ans.begin(), ans.end(), [](auto& a, auto& b) { return (a.second != b.second ? a.second > b.second : a.first < b.first); }); cout << ans.front().first << endl; }