結果
問題 |
No.575 n! / m / m / m...
|
ユーザー |
|
提出日時 | 2017-10-09 15:36:51 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 13 ms / 2,000 ms |
コード長 | 1,933 bytes |
コンパイル時間 | 1,062 ms |
コンパイル使用メモリ | 104,684 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-17 06:57:51 |
合計ジャッジ時間 | 2,244 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 23 |
ソースコード
#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 -= legendreFormula(n, m) * log(m); a /= log(10); long long digit = (long long)a; a -= digit; a *= log(10); printf("%.10fe%lld\n", exp(a), digit); return 0; }