結果
問題 | No.811 約数の個数の最大化 |
ユーザー | kyort0n |
提出日時 | 2019-04-12 21:52:30 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 19 ms / 2,000 ms |
コード長 | 1,504 bytes |
コンパイル時間 | 1,513 ms |
コンパイル使用メモリ | 167,208 KB |
実行使用メモリ | 4,352 KB |
最終ジャッジ日時 | 2023-10-12 19:52:14 |
合計ジャッジ時間 | 2,759 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,352 KB |
testcase_01 | AC | 2 ms
4,348 KB |
testcase_02 | AC | 16 ms
4,348 KB |
testcase_03 | AC | 2 ms
4,352 KB |
testcase_04 | AC | 2 ms
4,348 KB |
testcase_05 | AC | 2 ms
4,348 KB |
testcase_06 | AC | 3 ms
4,348 KB |
testcase_07 | AC | 3 ms
4,348 KB |
testcase_08 | AC | 9 ms
4,348 KB |
testcase_09 | AC | 9 ms
4,348 KB |
testcase_10 | AC | 6 ms
4,348 KB |
testcase_11 | AC | 17 ms
4,352 KB |
testcase_12 | AC | 6 ms
4,348 KB |
testcase_13 | AC | 19 ms
4,348 KB |
testcase_14 | AC | 18 ms
4,348 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> l_l; typedef pair<int, int> i_i; #define EPS (1e-7) #define INF (1e9) #define PI (acos(-1)) //const ll mod = 1000000007; vector<int> primes; int factor[100050]; int main() { //cout.precision(10); cin.tie(0); ios::sync_with_stdio(false); int N, K; cin >> N >> K; for(int i = 2; i <= 1000; i++) { bool ok = true; for(int j = 2; j * j <= i; j++) { if(i % j == 0) ok = false; } if(ok) primes.push_back(i); } int copy = N; for(int i = 2; i <= 1000; i++) { while(copy % i == 0) { factor[i]++; copy /= i; } } if(copy > 1) factor[copy]++; int ans = 1; int val = 0; for(int i = 2; i < N; i++) { copy = i; int now_val = 1; int now_k = 0; for(int j = 0; j < primes.size(); j++) { int p = primes[j]; if(p * p > copy) break; int now_factor = 0; while(copy % p == 0) { copy /= p; now_factor++; } now_k += min(now_factor, factor[p]); now_val *= (now_factor + 1); } if(copy > 1) { now_k += min(1, factor[copy]); now_val *= 2; } if(now_k < K) continue; if(now_val > val) { ans = i; val = now_val; } } cout << ans << endl; return 0; }