参考:非常好的博客!
#include <bits/stdc++.h>
using namespace std;
long long n,p;
long long inv[3000001],fac[3000001],finv[3000001];
typedef long long ll;
void xianxing()//线性
{
inv[1] = 1;
cout << 1 << endl;
for (int i = 2; i <= n; i++)
{
inv[i] = (p - p / i) * inv[p % i] % p;
printf("%lld\n",inv[i]);
}
}
void gcd(ll a,ll b,ll &x,ll &y)//扩展欧几里得
{
if(!b)x = 1,y = 0;
else gcd(b,a % b,y,x),y -= (a / b) * x;
}
void exou()
{
for (int i = 1; i <= n; i++)
{
ll x = 0,y = 0;
gcd(i,p,x,y);
x = ( x % p + p) % p;
printf("%lld\n",x);
}
}
void fm()
{
for (int i = 1; i <= n; i++)
{
ll ans = 1,base = i,pp = p - 2;
while(pp)
{
if(pp & 1)
{
ans = (ans * base) % p;
}
pp >>= 1;
base = (base * base) % p;
}
printf("%lld\n",ans);
}
}
void factorial()
{
fac[0] = 1;
for (int i = 1; i <= n; i++)
{
fac[i] = (fac[i - 1] * i ) % p;
}
ll x = 0,y = 0;
gcd(fac[n],p,x,y);
x = (x % p + p) % p;
finv[n] = x;
for (int i = n - 1; i > 0; i--)
{
finv[i] = finv[i + 1] * (i + 1) % p;
}
for (int i = 1; i <= n; i++)
{
printf("%lld\n",finv[i] * fac[i - 1] % p);
}
}
int main()
{
cin >> n >> p;
factorial();
return 0;
}
没什么好说的,明天就csps了,再见