結果

問題 No.575 n! / m / m / m...
ユーザー PachicobuePachicobue
提出日時 2017-10-07 03:04:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 135 ms / 2,000 ms
コード長 2,442 bytes
コンパイル時間 1,654 ms
コンパイル使用メモリ 170,380 KB
実行使用メモリ 12,848 KB
最終ジャッジ日時 2024-04-28 12:05:58
合計ジャッジ時間 4,355 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
12,724 KB
testcase_01 AC 123 ms
12,716 KB
testcase_02 AC 26 ms
12,724 KB
testcase_03 AC 26 ms
12,720 KB
testcase_04 AC 25 ms
12,720 KB
testcase_05 AC 24 ms
12,720 KB
testcase_06 AC 25 ms
12,464 KB
testcase_07 AC 27 ms
12,720 KB
testcase_08 AC 27 ms
12,716 KB
testcase_09 AC 25 ms
12,720 KB
testcase_10 AC 25 ms
12,592 KB
testcase_11 AC 26 ms
12,652 KB
testcase_12 AC 26 ms
12,620 KB
testcase_13 AC 28 ms
12,844 KB
testcase_14 AC 27 ms
12,720 KB
testcase_15 AC 27 ms
12,716 KB
testcase_16 AC 27 ms
12,720 KB
testcase_17 AC 122 ms
12,592 KB
testcase_18 AC 124 ms
12,720 KB
testcase_19 AC 132 ms
12,716 KB
testcase_20 AC 126 ms
12,596 KB
testcase_21 AC 128 ms
12,720 KB
testcase_22 AC 128 ms
12,720 KB
testcase_23 AC 134 ms
12,848 KB
testcase_24 AC 126 ms
12,720 KB
testcase_25 AC 135 ms
12,720 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define show(x) cerr << #x << " = " << x << endl

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz=" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}

template <typename S, typename T>
ostream& operator<<(ostream& os, const pair<S, T>& p)
{
    os << "(" << p.first << "," << p.second
       << ")";
    return os;
}


constexpr ll MOD = 1e9 + 7;

template <typename T>
constexpr T INF = numeric_limits<T>::max() / 100;

constexpr ll MAX = (ll)1e12;
constexpr ll SQRT = (ll)1e6;
bool isprime[SQRT + 1];

long double logsum(const ll n)
{
    long double sum = 0;
    constexpr ll LEV = 10000000;
    for (ll i = 2; i <= min(LEV, n); i++) {
        sum += (long double)log(i);
    }
    if (n > LEV) {
        sum += (n + 0.5) * (long double)log(n + 0.5) - (LEV + 0.5) * (long double)log(LEV + 0.5) - (n + 0.5) + (LEV + 0.5);
    }
    return sum;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m;
    cin >> n >> m;
    fill(isprime, isprime + SQRT + 1, true);
    for (ll i = 2; i <= SQRT; i++) {
        if (isprime[i]) {
            for (ll j = 2; i * j <= SQRT; j++) {
                isprime[i * j] = false;
            }
        }
    }
    vector<ll> prime;
    for (ll i = 2; i <= SQRT; i++) {
        prime.push_back(i);
    }

    ll cnt = INF<ll>;
    ll m_cop = m;
    for (const ll p : prime) {
        if (m_cop % p != 0) {
            continue;
        }
        ll d = 0;
        while (m_cop % p == 0) {
            d++;
            m_cop /= p;
        }

        ll candiv = 0;
        ll n_cop = n;
        while (n_cop > 0) {
            candiv += n_cop / p;
            n_cop /= p;
        }

        cnt = min(cnt, candiv / d);
    }
    if (m_cop > 1) {
        ll candiv = 0;
        ll n_cop = n;
        while (n_cop > 0) {
            candiv += n_cop / m_cop;
            n_cop /= m_cop;
        }
        cnt = min(cnt, candiv);
    }

    const long double restlog = logsum(n) - cnt * (long double)log(m);
    const ll d = (ll)(restlog / log(10));
    const long double rest = restlog - log(10) * d;
    constexpr long double E = 2.71828182845904523536028747135;
    cout << fixed << setprecision(10) << pow(E, rest) << "e" << d << endl;

    return 0;
}
0