結果

問題 No.575 n! / m / m / m...
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2017-10-07 11:01:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 2,243 bytes
コンパイル時間 1,598 ms
コンパイル使用メモリ 172,240 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-10 19:25:13
合計ジャッジ時間 2,941 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
typedef long long ll;
map<ll,int> enumpr(ll n) {
	map<ll,int> V;
	for(ll i=2;i*i<=n;i++) while(n%i==0) V[i]++,n/=i;
	if(n>1) V[n]++;
	return V;
}
/*---------------------------------------------------------------------------------------------------
            ∧_∧  
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     
    /   \     | |     
    /   / ̄ ̄ ̄ ̄/  |  
  __(__ニつ/     _/ .| .|____  
     \/____/ (u ⊃  
---------------------------------------------------------------------------------------------------*/




ll N, M;
//---------------------------------------------------------------------------------------------------
const double PI = 2 * acos(0.0), E = exp(1);
// スターリングの近似公式を使ってlog10(n!)を計算する
double log10facn(ll _n) {
    if (_n < 101010) {
        double res = 0;
        rep(i, 1, _n + 1) res += log10(i);
        return res;
    }
    double n = _n;
    return log10(2 * PI * N) / 2 + n * log10(n / E) + log10(1 + 1.0 / (12 * N));
}
// a!をbで最大何回割り切れるかを求める
ll legendreFormula(ll a, ll b) {
    auto e = enumpr(b);
    ll k = 1LL << 60;
    fore(p, e) {
        ll x = p.first;
        ll c = 0;
        while (x <= a) {
            c += a / x;
            x *= p.first;
        }
        k = min(k, c / (ll)p.second);
    }
    return k;
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> M;

    ll k = legendreFormula(N, M);

    double a = log10facn(N);
    double b = log10(M);

    double n = a - b * k;

    ll d = floor(n);

    n -= d;
    
    double nn = pow(10, n);
    printf("%.10fe%lld\n", nn, d);
}
0