# Submit Info #2770

Problem Lang User Status Time Memory
Montmort Number cpp (anonymous) AC 95 ms 13.92 MiB

ケース詳細
Name Status Time Memory
example_00 AC 4 ms 4.42 MiB
example_01 AC 3 ms 4.50 MiB
max_00 AC 95 ms 13.55 MiB
max_01 AC 89 ms 13.67 MiB
max_02 AC 84 ms 13.92 MiB
random_00 AC 36 ms 7.91 MiB
random_01 AC 41 ms 8.55 MiB
random_02 AC 55 ms 9.92 MiB
random_03 AC 38 ms 8.55 MiB
random_04 AC 72 ms 11.89 MiB

#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; //template #define rep(i,a,b) for(int i=(a);i<(b);i++) #define rrep(i,a,b) for(int i=(a);i>(b);i--) #define ALL(v) (v).begin(),(v).end() typedef long long int ll; const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12; void tostr(ll x,string& res){while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return;} template<class T> inline bool chmax(T& a,T b){ if(a<b){a=b;return 1;}return 0; } template<class T> inline bool chmin(T& a,T b){ if(a>b){a=b;return 1;}return 0; } //template end int mod=1e9+7; struct Mint { int val; int inv() const{ int tmp,a=val,b=mod,x=1,y=0; while(b)tmp=a/b,a-=tmp*b,swap(a,b),x-=tmp*y,swap(x,y); if(x<0)x+=mod; return x; } Mint():val(0){} Mint(ll x):val(x>=0?x%mod:mod+(x%mod)){} Mint pow(ll t){Mint res=1,b=*this; while(t){if(t&1)res*=b;b*=b;t>>=1;}return res;} Mint& operator+=(const Mint& x){if((val+=x.val)>=mod)val-=mod;return *this;} Mint& operator-=(const Mint& x){if((val+=mod-x.val)>=mod)val-=mod; return *this;} Mint& operator*=(const Mint& x){val=(ll)val*x.val%mod; return *this;} Mint& operator/=(const Mint& x){val=(ll)val*x.inv()%mod; return *this;} Mint operator+(const Mint& x)const{return Mint(*this)+=x;} Mint operator-(const Mint& x)const{return Mint(*this)-=x;} Mint operator*(const Mint& x)const{return Mint(*this)*=x;} Mint operator/(const Mint& x)const{return Mint(*this)/=x;} bool operator==(const Mint& x)const{return val==x.val;} bool operator!=(const Mint& x)const{return val!=x.val;} }; struct factorial { vector<Mint> Fact, Finv; public: factorial(int maxx){ Fact.resize(maxx+1),Finv.resize(maxx+1); Fact[0]=Mint(1); rep(i,0,maxx)Fact[i+1]=Fact[i]*(i+1); Finv[maxx]=Mint(1)/Fact[maxx]; rrep(i,maxx,0)Finv[i-1]=Finv[i]*i; } Mint fact(int n,bool inv=0){if(inv)return Finv[n];else return Fact[n];} Mint nPr(int n,int r){if(n<0||n<r||r<0)return Mint(0);else return Fact[n]*Finv[n-r];} Mint nCr(int n,int r){if(n<0||n<r||r<0)return Mint(0);else return Fact[n]*Finv[r]*Finv[n-r];} }; Mint dp[1010000]; int main(){ int n; scanf("%d%d",&n,&mod); dp[1]=0; dp[2]=1; rep(i,3,n+1)dp[i]=(dp[i-1]+dp[i-2])*(i-1); rep(i,1,n+1)printf("%d\n",dp[i].val); return 0; }