結果

問題 No.575 n! / m / m / m...
ユーザー rpy3cpprpy3cpp
提出日時 2017-10-07 01:19:21
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,394 bytes
コンパイル時間 1,479 ms
コンパイル使用メモリ 171,048 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-10 18:29:08
合計ジャッジ時間 4,479 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 7 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

vector<pair<long long, int>> factorize(long long n){
    vector<pair<long long, int>> fs;
    int k = 0;
    for (; n % 2 == 0; n /= 2, ++k);
    if (k > 0) fs.emplace_back(2, k);
    for (long long p = 3; p * p <= n; p += 2){
        k = 0;
        for(; n % p == 0; n /= p, ++k);
        if (k > 0) fs.emplace_back(p, k);
    }
    if (n > 1) fs.emplace_back(n, 1);
    return fs;
}

int find_q(long long n, const vector<pair<long long, int>> & fs){
    int q = 1e9;
    for (const auto &pk : fs){
        long long p = pk.first;
        int k = pk.second;
        long long nn = n;
        int kk = 0;
        for (; nn % p == 0; nn /= p, kk += nn);
        q = min(q, kk / k);
    }
    return q;
}

constexpr double pi = 3.14159265358979323846;

int main() {
    long long n, m;
    cin >> n >> m;
    auto fs = factorize(m);
    int q = find_q(n, fs);
    // log(n!/(m**q)) = log(n!) - q * log(m)
    // = n log(n) - n + log(2*pi*n)/2.0 + 1/(12*n) - 1/(360*n*n*n) - q * log(m)
    double ans;
    ans = (n * (log(1.0 * n) - 1.0) + 0.5 * log(2.0 * pi * n) + 1.0/12.0/n - 1.0/360.0/n/n/n + 1.0/1260.0/n/n/n/n/n - q * log(1.0 * m)) * log10(exp(1.0));
    long long d = floor(ans);
    ans -= d;
    double p = pow(10.0, ans);
    if (d < 0){
        cout << "1e0" << endl;
    }else{
        cout << p << 'e' << d << endl;
    }
    return 0;
}
0