Submit Info #12110

Problem Lang User Status Time Memory
Montmort Number cpp koosaga AC 92 ms 13.91 MiB

ケース詳細
Name Status Time Memory
example_00 AC 0 ms 0.59 MiB
example_01 AC 2 ms 0.67 MiB
max_00 AC 92 ms 13.41 MiB
max_01 AC 85 ms 13.61 MiB
max_02 AC 79 ms 13.91 MiB
random_00 AC 35 ms 5.55 MiB
random_01 AC 40 ms 6.42 MiB
random_02 AC 51 ms 8.17 MiB
random_03 AC 39 ms 6.23 MiB
random_04 AC 73 ms 11.20 MiB

#include <bits/stdc++.h> using namespace std; using lint = long long; int mod; struct mint { int val; mint() { val = 0; } mint(const lint& v) { val = (-mod <= v && v < mod) ? v : v % mod; if (val < 0) val += mod; } friend ostream& operator<<(ostream& os, const mint& a) { return os << a.val; } friend bool operator==(const mint& a, const mint& b) { return a.val == b.val; } friend bool operator!=(const mint& a, const mint& b) { return !(a == b); } friend bool operator<(const mint& a, const mint& b) { return a.val < b.val; } mint operator-() const { return mint(-val); } mint& operator+=(const mint& m) { if ((val += m.val) >= mod) val -= mod; return *this; } mint& operator-=(const mint& m) { if ((val -= m.val) < 0) val += mod; return *this; } mint& operator*=(const mint& m) { val = (lint)val*m.val%mod; return *this; } friend mint ipow(mint a, lint p) { mint ans = 1; for (; p; p /= 2, a *= a) if (p&1) ans *= a; return ans; } friend mint inv(const mint& a) { assert(a.val); return ipow(a, mod - 2); } mint& operator/=(const mint& m) { return (*this) *= inv(m); } friend mint operator+(mint a, const mint& b) { return a += b; } friend mint operator-(mint a, const mint& b) { return a -= b; } friend mint operator*(mint a, const mint& b) { return a *= b; } friend mint operator/(mint a, const mint& b) { return a /= b; } operator int64_t() const {return val; } }; int main(){ int n; cin >> n >> mod; vector<mint> dp(n + 2); dp[0] = mint(1); dp[1] = mint(0); for(int i=2; i<=n+1; i++){ printf("%lld ", (lint)dp[i-1]); dp[i] = mint(i - 1) * (dp[i-1] + dp[i-2]); } }