結果

問題 No.811 約数の個数の最大化
ユーザー 👑 jupirojupiro
提出日時 2020-01-23 17:36:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,541 bytes
コンパイル時間 1,170 ms
コンパイル使用メモリ 126,608 KB
実行使用メモリ 53,948 KB
最終ジャッジ日時 2023-09-26 17:31:46
合計ジャッジ時間 4,950 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 174 ms
53,112 KB
testcase_01 AC 181 ms
51,960 KB
testcase_02 WA -
testcase_03 AC 174 ms
53,408 KB
testcase_04 WA -
testcase_05 AC 173 ms
53,228 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 192 ms
53,416 KB
testcase_14 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long MAX = 5100000;
const long long INF = 1LL << 60;
const long long mod = 1000000007LL;
//const long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

bool IsPrime[MAX];
ll MinFactor[MAX];
vector<ll> preprocess(ll n = MAX) {
    vector<ll> res;
    for (ll i = 0; i < n; ++i) IsPrime[i] = true, MinFactor[i] = -1;
    IsPrime[0] = false; IsPrime[1] = false;
    MinFactor[0] = 0; MinFactor[1] = 1;
    for (ll i = 2; i < n; ++i) {
        if (IsPrime[i]) {
            MinFactor[i] = i;
            res.push_back(i);
            for (ll j = i * 2; j < n; j += i) {
                IsPrime[j] = false;
                if (MinFactor[j] == -1) MinFactor[j] = i;
            }
        }
    }
    return res;
}

vector<pair<ll, ll> > fast_prime_factor(ll n) {
    vector<pair<ll, ll> > res;
    while (n != 1) {
        ll prime = MinFactor[n];
        ll exp = 0;
        while (MinFactor[n] == prime) {
            ++exp;
            n /= prime;
        }
        res.push_back(make_pair(prime, exp));
    }
    return res;
}

int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/
    ll N, K; cin >> N >> K;
    preprocess();
    vector<pair<ll, ll>> np = fast_prime_factor(N);
    ll res = 0;
    ll cnt = 0;
    for (ll i = 2; i < N; i++) {
        ll tmp = 0;
        map<ll, ll> mp;
        vector<pair<ll, ll>> vp = fast_prime_factor(i);
        ll d_cnt = 1;
        for (auto p : vp) {
            mp[p.first] = p.second;
            d_cnt *= (p.second + 1);
        }
        for (auto p : np) {
            if (mp.find(p.first) != mp.end()) chmin(mp[p.first], p.second);
        }
        for (auto p : mp) {
            tmp += p.second;
        }
        if (K <= tmp) {
            if (cnt < d_cnt) {
                res = i;
                cnt = d_cnt;
            }
        }
    }
    cout << res << endl;
	return 0;
}
0