結果

問題 No.575 n! / m / m / m...
ユーザー parukiparuki
提出日時 2017-10-13 12:46:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,782 bytes
コンパイル時間 1,707 ms
コンパイル使用メモリ 167,184 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-28 17:27:43
合計ジャッジ時間 4,633 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 WA -
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,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 AC 12 ms
5,376 KB
testcase_24 WA -
testcase_25 AC 13 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

/*
Legendre's formula

nを自然数、pを素数とするとき
p^x | n!
を満たす最大の非負整数xを返す。
時間
O(log(n))

参考
https://en.wikipedia.org/wiki/Legendre%27s_formula
*/
long long LegendreFormula(long long n, long long p) {
    long long res = 0, d = p, a;
    while ((a = n / d) != 0) {
        res += a;
        d *= p;
    }
    return res;
}

/*
スターリングの近似
log(n!)の近似
https://ja.wikipedia.org/wiki/%E3%82%B9%E3%82%BF%E3%83%BC%E3%83%AA%E3%83%B3%E3%82%B0%E3%81%AE%E8%BF%91%E4%BC%BC
*/
double stirlingsApproximation(long long n) {
    return n * log(n) - n + 0.5*log(2 * M_PI*n) + 1.0/(12*n);
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    ll n, m, p;
    cin >> n >> m;
    double x = stirlingsApproximation(n);

    auto f = [&](ll p) {
        x -= LegendreFormula(n, p)*log(p);
    };
    for (p = 2; p*p <= m; ++p) {
        if (m%p == 0) {
            while (m%p == 0)m /= p;
            f(p);
        }
    }

    if (m != 1) {
        f(m);
    }
    double x10 = x / log(10.0);
    ll pw = (ll)x10;
    x10 -= pw;
    x = x10 * log(10);
    cout << exp(x) << 'e' << pw << endl;
}
0