結果
問題 | No.575 n! / m / m / m... |
ユーザー | Pachicobue |
提出日時 | 2017-10-07 03:04:29 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 137 ms / 2,000 ms |
コード長 | 2,442 bytes |
コンパイル時間 | 2,324 ms |
コンパイル使用メモリ | 170,056 KB |
実行使用メモリ | 12,852 KB |
最終ジャッジ日時 | 2024-11-17 03:28:44 |
合計ジャッジ時間 | 4,569 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 27 ms
12,592 KB |
testcase_01 | AC | 136 ms
12,704 KB |
testcase_02 | AC | 27 ms
12,720 KB |
testcase_03 | AC | 26 ms
12,716 KB |
testcase_04 | AC | 26 ms
12,468 KB |
testcase_05 | AC | 27 ms
12,672 KB |
testcase_06 | AC | 26 ms
12,720 KB |
testcase_07 | AC | 26 ms
12,848 KB |
testcase_08 | AC | 27 ms
12,724 KB |
testcase_09 | AC | 27 ms
12,592 KB |
testcase_10 | AC | 28 ms
12,724 KB |
testcase_11 | AC | 27 ms
12,468 KB |
testcase_12 | AC | 27 ms
12,716 KB |
testcase_13 | AC | 28 ms
12,596 KB |
testcase_14 | AC | 28 ms
12,460 KB |
testcase_15 | AC | 28 ms
12,720 KB |
testcase_16 | AC | 28 ms
12,852 KB |
testcase_17 | AC | 137 ms
12,720 KB |
testcase_18 | AC | 137 ms
12,720 KB |
testcase_19 | AC | 137 ms
12,592 KB |
testcase_20 | AC | 136 ms
12,720 KB |
testcase_21 | AC | 137 ms
12,720 KB |
testcase_22 | AC | 137 ms
12,724 KB |
testcase_23 | AC | 136 ms
12,724 KB |
testcase_24 | AC | 136 ms
12,848 KB |
testcase_25 | AC | 137 ms
12,724 KB |
ソースコード
#include <bits/stdc++.h> #define show(x) cerr << #x << " = " << x << endl using namespace std; using ll = long long; using pii = pair<int, int>; using vi = vector<int>; template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { os << "sz=" << v.size() << "\n["; for (const auto& p : v) { os << p << ","; } os << "]\n"; return os; } template <typename S, typename T> ostream& operator<<(ostream& os, const pair<S, T>& p) { os << "(" << p.first << "," << p.second << ")"; return os; } constexpr ll MOD = 1e9 + 7; template <typename T> constexpr T INF = numeric_limits<T>::max() / 100; constexpr ll MAX = (ll)1e12; constexpr ll SQRT = (ll)1e6; bool isprime[SQRT + 1]; long double logsum(const ll n) { long double sum = 0; constexpr ll LEV = 10000000; for (ll i = 2; i <= min(LEV, n); i++) { sum += (long double)log(i); } if (n > LEV) { sum += (n + 0.5) * (long double)log(n + 0.5) - (LEV + 0.5) * (long double)log(LEV + 0.5) - (n + 0.5) + (LEV + 0.5); } return sum; } int main() { cin.tie(0); ios::sync_with_stdio(false); ll n, m; cin >> n >> m; fill(isprime, isprime + SQRT + 1, true); for (ll i = 2; i <= SQRT; i++) { if (isprime[i]) { for (ll j = 2; i * j <= SQRT; j++) { isprime[i * j] = false; } } } vector<ll> prime; for (ll i = 2; i <= SQRT; i++) { prime.push_back(i); } ll cnt = INF<ll>; ll m_cop = m; for (const ll p : prime) { if (m_cop % p != 0) { continue; } ll d = 0; while (m_cop % p == 0) { d++; m_cop /= p; } ll candiv = 0; ll n_cop = n; while (n_cop > 0) { candiv += n_cop / p; n_cop /= p; } cnt = min(cnt, candiv / d); } if (m_cop > 1) { ll candiv = 0; ll n_cop = n; while (n_cop > 0) { candiv += n_cop / m_cop; n_cop /= m_cop; } cnt = min(cnt, candiv); } const long double restlog = logsum(n) - cnt * (long double)log(m); const ll d = (ll)(restlog / log(10)); const long double rest = restlog - log(10) * d; constexpr long double E = 2.71828182845904523536028747135; cout << fixed << setprecision(10) << pow(E, rest) << "e" << d << endl; return 0; }