1.快速幂+費馬小定理(當模數為質數可以用
// 快速幂求逆元
ll pow_mod(ll a, ll b, ll p){//a的b次方求餘p
ll ans = 1;
while(b){
if(b & 1) ans = (ans * a) % p;
a = (a * a) % p;
b >>= 1;
}
return ans;
}
ll inv(ll a, ll p){//費馬求a關于b的逆元
return pow_mod(a, p-2, p);
}
//x->a關于b的逆元
//y->b關于a的逆元
typedef long long ll
void ex_gcd(ll a, ll b, ll &x, ll &y, ll &d){
if (!b) {d = a, x = 1, y = 0;}
else{
ex_gcd(b, a % b, y, x, d);
y -= x * (a / b);
}
}
ll inv(ll t, ll p){//如果不存在,傳回-1
ll d, x, y;
ex_gcd(t, p, x, y, d);
return d == 1 ? (x % p + p) % p : -1;
}
#include <bits/stdc++.h>
using namespace std;
int inv[3000006];
int main()
{
int n,p;
scanf("%d%d",&n,&p);
inv[1]=1;
printf("1\n");
for(int i=2;i<=n;i++)
{
inv[i]=(ll)(p-p/i)*inv[p%i]%p;
printf("%d\n",inv[i]);
}
return 0;
}