Submission #36977132


Source Code Expand

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const double PI = acos(-1);

struct Sieve {
    int n;
    vector<int> f, primes;
    Sieve(int n=1):n(n), f(n+1) {
        f[0] = f[1] = -1;
        for (ll i = 2; i <= n; i++) {
            if (f[i]) continue;
            primes.push_back(i);
            f[i] = i;
            for (ll j = i*i; j <= n; j += i) {
                if (!f[j]) f[j] = i;
            }
        }
    }
    bool isPrime(int x) { return f[x] == x;}
    vector<int> factorList(int x) {
        vector<int> res;
        while (x != 1) {
            res.push_back(f[x]);
            x /= f[x];
        }
        return res;
    }
    vector<P> factor(int x) {
        vector<int> fl = factorList(x);
        if (fl.size() == 0) return {};
        vector<P> res(1, P(fl[0], 0));
        for (int p : fl) {
            if (res.back().first == p) {
                res.back().second++;
            } else {
                res.emplace_back(p, 1);
            }
        }
        return res;
    }
    vector<pair<ll,int>> factorL(ll x) {
        vector<pair<ll,int>> res;
        for (int p : primes) {
            int y = 0;
            while (x%p == 0) x /= p, ++y;
            if (y != 0) res.emplace_back(p,y);
        }
        if (x != 1) res.emplace_back(x,1);
        return res;
    }
};

vector<ll> yakusu(ll n) {
    vector<ll> res;
    for (ll i = 1; i*i <= n; i++) {
        if (n%i == 0) {
            res.push_back(i);
            if (n/i != i) res.push_back(n/i);
        }
    }
    sort(res.begin(), res.end());
    return res;
}

int main() {
    ll k;
    cin >> k;
    Sieve sieve(1000005);
    auto vec = sieve.factorL(k);
    ll ans = 1;
    for (auto p : vec) {
        auto [x, cnt] = p;
        ll l = 1, r = k+1;
        while (l+1 < r) {
            ll c = (l+r)/2;
            ll ev = x;
            ll cntnow = 0;
            while (c/ev > 0) {
                cntnow += c/ev;
                if (ev > 1e13/x) break;
                ev *= x;
            }
            if (cntnow >= cnt) r = c;
            else l = c;
        }
        chmax(ans, r);
    }
    cout << ans << endl;
    return 0;
}

Submission Info

Submission Time
Task D - Factorial and Multiple
User taki0711
Language C++ (GCC 9.2.1)
Score 400
Code Size 2583 Byte
Status AC
Exec Time 23 ms
Memory 7832 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 63
Set Name Test Cases
Sample example_00.txt, example_01.txt, example_02.txt
All example_00.txt, example_01.txt, example_02.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, hand_10.txt, hand_11.txt, hand_12.txt, hand_13.txt, hand_14.txt, hand_15.txt, hand_16.txt, hand_17.txt, hand_18.txt, hand_19.txt, hand_20.txt, hand_21.txt, hand_22.txt, hand_23.txt, hand_24.txt, hand_25.txt, hand_26.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt
Case Name Status Exec Time Memory
example_00.txt AC 16 ms 7620 KiB
example_01.txt AC 15 ms 7752 KiB
example_02.txt AC 15 ms 7684 KiB
hand_00.txt AC 16 ms 7696 KiB
hand_01.txt AC 16 ms 7700 KiB
hand_02.txt AC 17 ms 7672 KiB
hand_03.txt AC 16 ms 7692 KiB
hand_04.txt AC 15 ms 7620 KiB
hand_05.txt AC 23 ms 7688 KiB
hand_06.txt AC 14 ms 7756 KiB
hand_07.txt AC 16 ms 7672 KiB
hand_08.txt AC 15 ms 7748 KiB
hand_09.txt AC 15 ms 7816 KiB
hand_10.txt AC 15 ms 7700 KiB
hand_11.txt AC 15 ms 7820 KiB
hand_12.txt AC 15 ms 7768 KiB
hand_13.txt AC 15 ms 7688 KiB
hand_14.txt AC 15 ms 7628 KiB
hand_15.txt AC 15 ms 7624 KiB
hand_16.txt AC 16 ms 7692 KiB
hand_17.txt AC 15 ms 7688 KiB
hand_18.txt AC 15 ms 7624 KiB
hand_19.txt AC 16 ms 7756 KiB
hand_20.txt AC 18 ms 7768 KiB
hand_21.txt AC 15 ms 7620 KiB
hand_22.txt AC 14 ms 7628 KiB
hand_23.txt AC 17 ms 7768 KiB
hand_24.txt AC 17 ms 7624 KiB
hand_25.txt AC 18 ms 7692 KiB
hand_26.txt AC 15 ms 7620 KiB
random_00.txt AC 16 ms 7620 KiB
random_01.txt AC 15 ms 7684 KiB
random_02.txt AC 21 ms 7688 KiB
random_03.txt AC 16 ms 7748 KiB
random_04.txt AC 17 ms 7620 KiB
random_05.txt AC 15 ms 7684 KiB
random_06.txt AC 18 ms 7684 KiB
random_07.txt AC 15 ms 7688 KiB
random_08.txt AC 20 ms 7824 KiB
random_09.txt AC 15 ms 7692 KiB
random_10.txt AC 14 ms 7696 KiB
random_11.txt AC 19 ms 7620 KiB
random_12.txt AC 15 ms 7752 KiB
random_13.txt AC 16 ms 7636 KiB
random_14.txt AC 16 ms 7696 KiB
random_15.txt AC 15 ms 7688 KiB
random_16.txt AC 21 ms 7832 KiB
random_17.txt AC 15 ms 7620 KiB
random_18.txt AC 15 ms 7624 KiB
random_19.txt AC 19 ms 7752 KiB
random_20.txt AC 18 ms 7640 KiB
random_21.txt AC 16 ms 7828 KiB
random_22.txt AC 14 ms 7692 KiB
random_23.txt AC 15 ms 7820 KiB
random_24.txt AC 15 ms 7692 KiB
random_25.txt AC 15 ms 7692 KiB
random_26.txt AC 15 ms 7764 KiB
random_27.txt AC 19 ms 7688 KiB
random_28.txt AC 21 ms 7756 KiB
random_29.txt AC 16 ms 7636 KiB
random_30.txt AC 17 ms 7748 KiB
random_31.txt AC 15 ms 7624 KiB
random_32.txt AC 17 ms 7696 KiB