結果
問題 | No.811 約数の個数の最大化 |
ユーザー |
|
提出日時 | 2019-04-12 21:44:19 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 57 ms / 2,000 ms |
コード長 | 1,088 bytes |
コンパイル時間 | 841 ms |
コンパイル使用メモリ | 83,476 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-14 17:53:48 |
合計ジャッジ時間 | 1,801 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 12 |
ソースコード
#include<iostream> #include<vector> #include<map> using namespace std; typedef long long ll; int main(){ bool nonp[100001] = {}; vector<int> p; for(int i = 2; i < 100001; i++){ if(nonp[i]) continue; p.push_back(i); for(int j = i+i; j < 100001; j += i) nonp[j] = true; } int N, k; cin >> N >> k; int n = N; map<int, int> fact; for(int prime : p){ while(n%prime == 0){ n /= prime; fact[prime]++; } } if(n != 1) fact[n]++; n = N; int ans = -1; ll score = 0; for(int i = 1; i < n; i++){ map<int,int> use; int cp = i; for(int j = 2; j*j <= cp; j++){ while(cp%j == 0) cp /= j, use[j]++; } if(cp != 1) use[cp]++; int tmp = 0; ll tmps = 1; for(auto x : use){ int add = min(x.second, fact[x.first]); tmp += add; tmps *= x.second+1; } if(tmp >= k && tmps > score) ans = i, score = tmps; } cout << ans << endl; return 0; }