Submit Info #3114

Problem Lang User Status Time Memory
Montmort Number cpp Haar AC 90 ms 17.75 MiB

ケース詳細
Name Status Time Memory
example_00 AC 26 ms 8.30 MiB
example_01 AC 26 ms 8.30 MiB
max_00 AC 90 ms 17.30 MiB
max_01 AC 88 ms 17.42 MiB
max_02 AC 87 ms 17.75 MiB
random_00 AC 51 ms 11.80 MiB
random_01 AC 55 ms 12.30 MiB
random_02 AC 62 ms 13.67 MiB
random_03 AC 54 ms 12.30 MiB
random_04 AC 76 ms 15.80 MiB

#include <bits/stdc++.h> #define LLI long long int #define FOR(v, a, b) for(LLI v = (a); v < (b); ++v) #define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v) #define REP(v, n) FOR(v, 0, n) #define REPE(v, n) FORE(v, 0, n) #define REV(v, a, b) for(LLI v = (a); v >= (b); --v) #define ALL(x) (x).begin(), (x).end() #define RALL(x) (x).rbegin(), (x).rend() #define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it) #define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it) #define EXIST(c,x) ((c).find(x) != (c).end()) #define fst first #define snd second #define popcount __builtin_popcount #define UNIQ(v) (v).erase(unique(ALL(v)), (v).end()) #define bit(i) (1LL<<(i)) #ifdef DEBUG #include <Mylib/Debug/debug.cpp> #else #define dump(...) ((void)0) #endif #define gcd __gcd using namespace std; template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;} template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;} template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;} template <typename T> void puts_all(const T &value){std::cout << value << "\n";} template <typename T, typename ...Args> void puts_all(const T &value, const Args&... args){std::cout << value << " ";puts_all(args...);} template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);} template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);} template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);} template <typename T> auto make_vector(int n, int m, const T &value){return vector<vector<T>>(n, vector<T>(m, value));} struct Init{ Init(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(12); cerr << fixed << setprecision(12); } }init; /** * @attention 使用前にstatic変数Mを設定する。 */ class RuntimeModInt{ public: static std::uint32_t M; std::uint64_t val; RuntimeModInt(): val(0){} RuntimeModInt(std::int64_t n){ if(n >= M) val = n % M; else if(n < 0) val = n % M + M; else val = n; } const RuntimeModInt operator+(const RuntimeModInt &a) const {return RuntimeModInt((val+a.val)%M);} const RuntimeModInt operator-(const RuntimeModInt &a) const {return RuntimeModInt((val-a.val+M)%M);} const RuntimeModInt operator*(const RuntimeModInt &a) const {return RuntimeModInt((val*a.val)%M);} const RuntimeModInt operator/(const RuntimeModInt &a) const {return RuntimeModInt((val*a.inv().val)%M);} const RuntimeModInt& operator=(const RuntimeModInt &a){val = a.val; return *this;} const RuntimeModInt& operator+=(const RuntimeModInt &a){if((val += a.val) >= M) val -= M; return *this;} const RuntimeModInt& operator-=(const RuntimeModInt &a){if(val < a.val) val += M; val -= a.val; return *this;} const RuntimeModInt& operator*=(const RuntimeModInt &a){(val *= a.val) %= M; return *this;} const RuntimeModInt& operator/=(const RuntimeModInt &a){(val *= a.inv().val) %= M; return *this;} const bool operator==(const RuntimeModInt &a) const {return val==a.val;} const bool operator!=(const RuntimeModInt &a) const {return val!=a.val;} const static RuntimeModInt power(std::int64_t n, std::int64_t p){ RuntimeModInt ret = 1, e = n; for(; p; e *= e, p >>= 1) if(p&1) ret *= e; return ret; } const RuntimeModInt power(std::int64_t p) const { RuntimeModInt ret = 1, e = val; for(; p; e *= e, p >>= 1) if(p&1) ret *= e; return ret; } const RuntimeModInt inv() const { std::int64_t a = val, b = M, u = 1, v = 0; while(b){ std::int64_t t = a/b; a -= t*b; std::swap(a,b); u -= t*v; std::swap(u,v); } u %= M; if(u < 0) u += M; return u; } }; RuntimeModInt operator-(const RuntimeModInt &a){return RuntimeModInt(-a.val);} RuntimeModInt operator+(std::int64_t a, const RuntimeModInt &b){return RuntimeModInt(RuntimeModInt(a)+b.val);} RuntimeModInt operator-(std::int64_t a, const RuntimeModInt &b){return RuntimeModInt(RuntimeModInt(a)-b.val);} RuntimeModInt operator*(std::int64_t a, const RuntimeModInt &b){return RuntimeModInt(RuntimeModInt(a)*b.val);} RuntimeModInt operator/(std::int64_t a, const RuntimeModInt &b){return RuntimeModInt(RuntimeModInt(a)/b.val);} std::uint32_t RuntimeModInt::M; std::istream& operator>>(std::istream &is, RuntimeModInt &a){is >> a.val; return is;} std::ostream& operator<<(std::ostream &os, const RuntimeModInt &a){ os << a.val; return os;} /** * @brief 1..nの順列を並び変えた時にどの要素も元の要素と異なるような並び替えの総数。 */ template <typename T> std::vector<T> montmort_number(int n){ std::vector<T> ret(n+1); ret[0] = 1; ret[1] = 0; ret[2] = 1; for(int i = 3; i <= n; ++i){ ret[i] = (ret[i-1]+ret[i-2]) * (i-1); } return ret; } using mint = RuntimeModInt; int main(){ int N, M; cin >> N >> M; mint::M = M; auto ans = montmort_number<mint>(1000000); join(cout, ans.begin() + 1, ans.begin() + N + 1); return 0; }