結果
問題 | No.502 階乗を計算するだけ |
ユーザー | kuhaku |
提出日時 | 2020-12-06 04:02:58 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 8,222 bytes |
コンパイル時間 | 2,314 ms |
コンパイル使用メモリ | 210,928 KB |
実行使用メモリ | 53,320 KB |
最終ジャッジ日時 | 2024-09-17 00:50:16 |
合計ジャッジ時間 | 8,260 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 81 ms
53,060 KB |
testcase_01 | AC | 82 ms
53,060 KB |
testcase_02 | AC | 83 ms
53,184 KB |
testcase_03 | AC | 82 ms
53,028 KB |
testcase_04 | AC | 83 ms
53,064 KB |
testcase_05 | AC | 82 ms
53,064 KB |
testcase_06 | AC | 82 ms
53,060 KB |
testcase_07 | AC | 82 ms
53,060 KB |
testcase_08 | AC | 82 ms
53,188 KB |
testcase_09 | AC | 81 ms
53,192 KB |
testcase_10 | AC | 85 ms
53,192 KB |
testcase_11 | AC | 86 ms
53,188 KB |
testcase_12 | AC | 84 ms
53,072 KB |
testcase_13 | AC | 104 ms
53,316 KB |
testcase_14 | AC | 104 ms
53,320 KB |
testcase_15 | AC | 81 ms
53,188 KB |
testcase_16 | AC | 82 ms
53,204 KB |
testcase_17 | AC | 81 ms
53,316 KB |
testcase_18 | AC | 81 ms
53,060 KB |
testcase_19 | AC | 83 ms
53,060 KB |
testcase_20 | AC | 82 ms
52,976 KB |
testcase_21 | AC | 82 ms
53,188 KB |
testcase_22 | AC | 82 ms
53,060 KB |
testcase_23 | AC | 83 ms
53,180 KB |
testcase_24 | AC | 83 ms
53,060 KB |
testcase_25 | AC | 81 ms
53,060 KB |
testcase_26 | AC | 82 ms
53,316 KB |
testcase_27 | AC | 82 ms
53,048 KB |
testcase_28 | AC | 87 ms
52,984 KB |
testcase_29 | AC | 82 ms
53,312 KB |
testcase_30 | AC | 84 ms
53,060 KB |
testcase_31 | AC | 82 ms
53,060 KB |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | AC | 83 ms
53,312 KB |
testcase_43 | AC | 85 ms
53,060 KB |
testcase_44 | AC | 82 ms
53,020 KB |
testcase_45 | AC | 82 ms
53,188 KB |
testcase_46 | AC | 85 ms
53,320 KB |
testcase_47 | AC | 82 ms
53,012 KB |
testcase_48 | AC | 82 ms
53,032 KB |
testcase_49 | AC | 82 ms
53,064 KB |
testcase_50 | AC | 83 ms
53,192 KB |
testcase_51 | AC | 81 ms
53,192 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = int64_t; using ld = long double; using P = pair<ll, ll>; using Pld = pair<ld, ld>; using Vec = vector<ll>; using VecP = vector<P>; using VecB = vector<bool>; using VecC = vector<char>; using VecD = vector<ld>; using VecS = vector<string>; template <class T> using Vec2 = vector<vector<T>>; #define REP(i, m, n) for(ll i = (m); i < (n); ++i) #define REPN(i, m, n) for(ll i = (m); i <= (n); ++i) #define REPR(i, m, n) for(ll i = (m)-1; i >= (n); --i) #define REPNR(i, m, n) for(ll i = (m); i >= (n); --i) #define rep(i, n) REP(i, 0, n) #define repn(i, n) REPN(i, 1, n) #define repr(i, n) REPR(i, n, 0) #define repnr(i, n) REPNR(i, n, 1) #define all(s) (s).begin(), (s).end() template <class T1, class T2> bool chmax(T1 &a, const T2 b) { if (a < b) { a = b; return true; } return false; } template <class T1, class T2> bool chmin(T1 &a, const T2 b) { if (a > b) { a = b; return true; } return false; } template <class T> istream &operator>>(istream &is, vector<T> &v) { for (T &i : v) is >> i; return is; } template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &i : v) os << i << ' '; return os; } void co() { cout << '\n'; } template <class Head, class... Tail> void co(Head&& head, Tail&&... tail) { cout << head << ' '; co(forward<Tail>(tail)...); } void ce() { cerr << '\n'; } template <class Head, class... Tail> void ce(Head&& head, Tail&&... tail) { cerr << head << ' '; ce(forward<Tail>(tail)...); } void sonic() { ios::sync_with_stdio(false); cin.tie(nullptr); } void setp(const int n) { cout << fixed << setprecision(n); } constexpr int64_t LINF = 1000000000000000001; constexpr int64_t MOD = 1000000007; constexpr int64_t MOD_N = 998244353; constexpr long double EPS = 1e-11; const double PI = acos(-1); template <int mod> struct ModInt { int64_t x; ModInt() : x(0) {} ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {} ModInt &operator+=(const ModInt &rhs) { if((x += rhs.x) >= mod) x -= mod; return *this; } ModInt &operator-=(const ModInt &rhs) { if((x += mod - rhs.x) >= mod) x -= mod; return *this; } ModInt &operator*=(const ModInt &rhs) { x = (int) (1LL * x * rhs.x % mod); return *this; } ModInt &operator/=(const ModInt &rhs) { *this *= rhs.inverse(); return *this; } ModInt &operator++() { if((++x) >= mod) x -= mod; return *this; } ModInt operator++(int) { ModInt tmp(*this); operator++(); return tmp; } ModInt &operator--() { if((x += mod - 1) >= mod) x -= mod; return *this; } ModInt operator--(int) { ModInt tmp(*this); operator--(); return tmp; } ModInt operator-() const { return ModInt(-x); } ModInt operator+(const ModInt &rhs) const { return ModInt(*this) += rhs; } ModInt operator-(const ModInt &rhs) const { return ModInt(*this) -= rhs; } ModInt operator*(const ModInt &rhs) const { return ModInt(*this) *= rhs; } ModInt operator/(const ModInt &rhs) const { return ModInt(*this) /= rhs; } bool operator==(const ModInt &rhs) const { return x == rhs.x; } bool operator!=(const ModInt &rhs) const { return x != rhs.x; } ModInt inverse() const { int a = x, b = mod, u = 1, v = 0, t; while (b > 0) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); } return ModInt(u); } ModInt pow(int64_t n) const { ModInt res(1), mul(x); while (n > 0) { if(n & 1) res *= mul; mul *= mul; n >>= 1; } return res; } void pow_self(int64_t n) { ModInt tmp = pow(n); swap(*this, tmp); } friend ostream &operator<<(ostream &os, const ModInt &rhs) { return os << rhs.x; } friend istream &operator>>(istream &is, ModInt &rhs) { int64_t t; is >> t; rhs = ModInt< mod >(t); return (is); } int to_int() const { return x; } static int get_mod() { return mod; } }; using Mint = ModInt<MOD>; struct prime_number { vector<int64_t> data; prime_number() { init(); } void init() { constexpr int sz = 4194304; bitset<sz> is_not_prime; is_not_prime[0] = is_not_prime[1] = true; for (int64_t i = 2; i < sz; ++i) { if (!is_not_prime[i]) { data.push_back(i); for (int64_t j = 2; i * j < sz; ++j) { is_not_prime[i * j] = true; } } } } bool is_prime(int64_t n) { if (n == 1) return false; for (auto i : data) { if (i * i > n) break; if (n % i == 0) return false; } return true; } vector<pair<int64_t, int64_t>> prime_factorization(int64_t n) { vector<pair<int64_t, int64_t>> res; for (auto i : data) { int64_t cnt = 0; while (n % i == 0) { n /= i; cnt++; } if (cnt) res.push_back({i, cnt}); if (n < i * i) break; } if (n != 1) res.push_back({n, 1}); return res; } int64_t pow_int(int64_t x, int64_t n) { int64_t res = 1; while (n) { if (n & 1) res *= x; x *= x; n >>= 1; } return res; } vector<int64_t> divisors(int64_t n) { auto v = prime_factorization(n); vector<int64_t> res, a, b, cp; res.push_back(1); for (auto p : v) { cp.resize(res.size()); copy(res.begin(), res.end(), cp.begin()); a.resize(res.size()); for (int64_t k = 1; k <= p.second; ++k) { int64_t t = pow_int(p.first, k); for (int64_t i = 0; i < a.size(); ++i) a[i] = cp[i] * t; merge(res.begin(), res.end(), a.begin(), a.end(), back_inserter(b)); swap(res, b); b.clear(); } } return res; } }; prime_number pn; template <int mod> struct math_mod { using mint = ModInt<mod>; vector<mint> fac, finv; math_mod() { _init(3000000); } void _init(const int64_t n) { if (fac.size() > n) return; const int m = fac.size(); fac.resize(n + 1); for (int64_t i = m; i <= n; ++i) { if (i == 0) fac[i] = 1; else fac[i] = fac[i - 1] * i; } finv.resize(n + 1); finv[n] = fac[n].inverse(); for (int64_t i = n - 1; i >= m; --i) finv[i] = finv[i + 1] * (i + 1); } mint fact(int64_t x) { assert(x >= 0 && x < fac.size()); return fac[x]; } mint combi(int64_t n, int64_t k) { if (n < k || n < 0 || k < 0) return 0; _init(n); return fac[n] * finv[k] * finv[n - k]; } mint combi_naive(int64_t n, int64_t k) { if (n - k < k) n = n - k; if (n < k || n < 0 || k < 0) return 0; mint res = 1; for (int64_t i = 0; i < k; ++i) { res *= n - i; res /= i + 1; } return res; } mint permu(int64_t n, int64_t k) { if (n < k || n < 0 || k < 0) return 0; _init(n); return fac[n] * finv[n - k]; } mint factorial(int64_t n) { if (n > 4000000) return 0; mint ans = 1; for (auto p : pn.data) { if (n < p) break; int64_t c = 0, t = p; while (t <= n) { c += n / t; t *= p; } ans *= mint(p).pow(c); } return ans; } }; math_mod<MOD> math; int main(void) { ll n; cin >> n; co(math.factorial(n)); return 0; }