結果
問題 | No.575 n! / m / m / m... |
ユーザー |
![]() |
提出日時 | 2017-10-07 11:01:28 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 13 ms / 2,000 ms |
コード長 | 2,243 bytes |
コンパイル時間 | 1,694 ms |
コンパイル使用メモリ | 173,572 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-17 04:23:03 |
合計ジャッジ時間 | 2,790 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 23 |
ソースコード
#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);}