結果
問題 |
No.575 n! / m / m / m...
|
ユーザー |
|
提出日時 | 2017-10-09 15:34:17 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,937 bytes |
コンパイル時間 | 978 ms |
コンパイル使用メモリ | 105,024 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-11-17 06:57:48 |
合計ジャッジ時間 | 3,298 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 14 WA * 9 |
ソースコード
#define _USE_MATH_DEFINES #include <cstdio> #include <iostream> #include <sstream> #include <fstream> #include <iomanip> #include <algorithm> #include <cmath> #include <complex> #include <string> #include <vector> #include <list> #include <queue> #include <stack> #include <set> #include <map> #include <bitset> #include <numeric> #include <limits> #include <climits> #include <cfloat> #include <functional> #include <iterator> using namespace std; void integerFactorization(long long n, vector<pair<long long, int> >& factor) { factor.clear(); long long a = 2; while(a * a <= n){ int b = 0; while(n % a == 0){ ++ b; n /= a; } if(b > 0) factor.push_back(make_pair(a, b)); ++ a; } if(n > 1) factor.push_back(make_pair(n, 1)); } long long legendreFormula(long long n, long long a) { vector<pair<long long, int> > factor; integerFactorization(a, factor); long long ans = LLONG_MAX; for(const auto& p : factor){ long long b = 1; long long cnt = 0; while(b <= n / p.first){ b *= p.first; cnt += n / b; } ans = min(ans, cnt / p.second); } return ans; } double stirlingApproximation(long long n) { double ans = 0.0; if(n <= 20){ // nが小さいと近似精度が低いため愚直に計算する for(int i=1; i<=n; ++i) ans += log(i); } else{ ans = log(2.0 * M_PI * n) / 2.0 + n * log(n / M_E) + log(1.0 + (1.0 / 12.0 + (1.0 / 288.0 - 139.0 / 51840.0 / n) / n) / n); } return ans; } int main() { long long n, m; cin >> n >> m; double a = stirlingApproximation(n); a -= log(pow(m, legendreFormula(n, m))); a /= log(10); long long digit = (long long)a; a -= digit; a *= log(10); printf("%.10fe%lld\n", exp(a), digit); return 0; }