結果

問題 No.575 n! / m / m / m...
ユーザー mamekinmamekin
提出日時 2017-10-09 15:36:51
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 1,933 bytes
コンパイル時間 847 ms
コンパイル使用メモリ 103,904 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-10 21:13:43
合計ジャッジ時間 2,280 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

void integerFactorization(long long n, vector<pair<long long, int> >& factor)
{
    factor.clear();
    long long a = 2;
    while(a * a <= n){
        int b = 0;
        while(n % a == 0){
            ++ b;
            n /= a;
        }
        if(b > 0)
            factor.push_back(make_pair(a, b));
        ++ a;
    }
    if(n > 1)
        factor.push_back(make_pair(n, 1));
}

long long legendreFormula(long long n, long long a)
{
    vector<pair<long long, int> > factor;
    integerFactorization(a, factor);

    long long ans = LLONG_MAX;
    for(const auto& p : factor){
        long long b = 1;
        long long cnt = 0;
        while(b <= n / p.first){
            b *= p.first;
            cnt += n / b;
        }
        ans = min(ans, cnt / p.second);
    }
    return ans;
}

double stirlingApproximation(long long n)
{
    double ans = 0.0;
    if(n <= 20){
        // nが小さいと近似精度が低いため愚直に計算する
        for(int i=1; i<=n; ++i)
            ans += log(i);
    }
    else{
        ans = log(2.0 * M_PI * n) / 2.0 + n * log(n / M_E) +
              log(1.0 + (1.0 / 12.0 + (1.0 / 288.0 - 139.0 / 51840.0 / n) / n) / n);
    }
    return ans;
}

int main()
{
    long long n, m;
    cin >> n >> m;

    double a = stirlingApproximation(n);
    a -= legendreFormula(n, m) * log(m);
    a /= log(10);

    long long digit = (long long)a;
    a -= digit;

    a *= log(10);
    printf("%.10fe%lld\n", exp(a), digit);

    return 0;
}
0