結果

問題 No.575 n! / m / m / m...
ユーザー imulanimulan
提出日時 2017-10-07 18:03:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,289 bytes
コンパイル時間 1,640 ms
コンパイル使用メモリ 174,776 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-28 12:51:48
合計ジャッジ時間 5,330 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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;
}

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);
    }
    dbg(ct);

    double v = stirling(n) - ct*log(m);
    v /= log(10);

    ll d = v;
    double ans = pow(10,v-d);

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