結果

問題 No.575 n! / m / m / m...
ユーザー imulanimulan
提出日時 2017-10-07 18:09:26
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 1,385 bytes
コンパイル時間 1,657 ms
コンパイル使用メモリ 172,496 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-10 19:33:52
合計ジャッジ時間 3,087 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const double PI = acos(-1);

map<ll,int> factorize(ll n)
{
    map<ll,int> ret;

    ll t = n;
    for(ll i=2; i*i<=n; ++i)
    {
        while(t%i==0)
        {
            ++ret[i];
            t/=i;
        }
    }
    if(t>1) ++ret[t];

    return ret;
}

double stirling(ll n)
{
    return n*(log(n)-1) + log(sqrt(2*PI*n));
}

ll num(ll n, ll prime)
{
    ll a = prime;
    ll ret = 0;
    while(a<=n)
    {
        ret += n/a;
        a*=prime;
    }
    return ret;
}

double fact(ll n)
{
    if(n==1) return 0;
    return log(n) + fact(n-1);
}

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

    ll ct = LLONG_MAX;
    for(const auto &p:factorize(m)) ct = min(ct, num(n,p.fi)/p.se);

    double v;
    if(n<1000) v = fact(n);
    else v = stirling(n);
    v -= ct*log(m);
    v /= log(10);
    
    ll d = v;
    double ans = pow(10,v-d);

    printf("%.10fe%lld\n", ans,d);
    return 0;
}
0