結果
問題 | No.811 約数の個数の最大化 |
ユーザー | betrue12 |
提出日時 | 2019-04-12 21:41:04 |
言語 | C++14 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 52 ms / 2,000 ms |
コード長 | 1,308 bytes |
コンパイル時間 | 1,775 ms |
コンパイル使用メモリ | 179,304 KB |
実行使用メモリ | 4,352 KB |
最終ジャッジ日時 | 2023-10-12 19:22:23 |
合計ジャッジ時間 | 2,958 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge14 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
4,348 KB |
testcase_01 | AC | 3 ms
4,348 KB |
testcase_02 | AC | 52 ms
4,352 KB |
testcase_03 | AC | 3 ms
4,352 KB |
testcase_04 | AC | 3 ms
4,348 KB |
testcase_05 | AC | 3 ms
4,352 KB |
testcase_06 | AC | 6 ms
4,348 KB |
testcase_07 | AC | 8 ms
4,348 KB |
testcase_08 | AC | 25 ms
4,348 KB |
testcase_09 | AC | 29 ms
4,348 KB |
testcase_10 | AC | 18 ms
4,348 KB |
testcase_11 | AC | 47 ms
4,348 KB |
testcase_12 | AC | 16 ms
4,348 KB |
testcase_13 | AC | 51 ms
4,352 KB |
testcase_14 | AC | 50 ms
4,348 KB |
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内: main.cpp:59:13: 警告: ‘ans’ may be used uninitialized [-Wmaybe-uninitialized] 59 | cout << ans << endl; | ^~~ main.cpp:34:9: 備考: ‘ans’ はここで定義されています 34 | int ans; | ^~~
ソースコード
#include <bits/stdc++.h> using namespace std; vector<int64_t> sieve(int64_t n){ vector<int64_t> ret; vector<bool> is_prime(n+1); for(int64_t i=2; i<=n; i++) is_prime[i] = true; for(int64_t i=2; i<=n; i++){ if(is_prime[i]){ ret.push_back(i); for(int64_t j=2*i; j<=n; j+=i) is_prime[j] = false; } } return ret; } int main(){ int N, K; cin >> N >> K; auto primes = sieve(100000); map<int, int> pn; int num = N; for(int64_t p : primes){ if(p*p > num) break; while(num % p == 0){ pn[p]++; num /= p; } } if(num > 1) pn[num]++; int mx = 0; int ans; for(int i=1; i<N; i++){ map<int, int> pi; int num = i; for(int64_t p : primes){ if(p*p > num) break; while(num % p == 0){ pi[p]++; num /= p; } } if(num > 1) pi[num]++; int k = 0; for(auto& p : pn){ k += min(p.second, pi[p.first]); } if(k < K) continue; int result = 1; for(auto& p : pi) result *= 1+p.second; if(mx < result){ mx = result; ans = i; } } cout << ans << endl; return 0; }