結果
問題 | No.811 約数の個数の最大化 |
ユーザー |
![]() |
提出日時 | 2020-03-06 14:33:59 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 131 ms / 2,000 ms |
コード長 | 2,170 bytes |
コンパイル時間 | 1,736 ms |
コンパイル使用メモリ | 178,720 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-14 02:47:42 |
合計ジャッジ時間 | 2,708 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 12 |
ソースコード
#include <bits/stdc++.h>using namespace std;typedef long long ll;#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)#define all(x) (x).begin(), (x).end()#define sz(x) ((ll)(x).size())#define len(x) ((ll)(x).length())vector<pair<ll, ll>> factorize(ll n) {vector<pair<ll, ll>> res;for (ll i = 2; (i * i) <= n; i++) {if (n % i) continue;res.emplace_back(i, 0);while((n % i) == 0) {n /= i;res.back().second++;}}if (n != 1) res.emplace_back(n, 1);return res;}ll faccnt(ll n) {auto fac = factorize(n);set<ll> s;s.insert(1);rep(i, sz(fac)) {rep(j, fac[i].second) {set<ll> add;for(auto x : s) add.insert(x * fac[i].first);for(auto x : add) s.insert(x);}}return sz(s);}int main() {cin.tie(0);ios::sync_with_stdio(false);// ifstream in("input.txt");// cin.rdbuf(in.rdbuf());ll n, k;cin >> n >> k;auto fac = factorize(n);vector<set<ll>> vs(k + 1);vs[0].insert(1);rep(i, k) {rrep(j, i + 1) {for (auto x : vs[j]) {rep(l, sz(fac)) {ll cnt = 0, cur = x;while(cur % fac[l].first == 0) {cnt++;cur /= fac[l].first;}if (cnt < fac[l].second) {vs[j + 1].insert(x * fac[l].first);}}}}}ll mv = 0, ans = 0;reps(i, 1, n) {bool f = false;for(auto x : vs[k]) {if (i % x == 0) {f = true;break;}}if (!f) continue;auto fi = factorize(i);ll cnt = faccnt(i);if (cnt > mv) {mv = cnt;ans = i;}}cout << ans << endl;return 0;}