逆元定义:若a*x=1(mod p),(a,p互质),则x为a mod p意义下的逆元
做法见https://www.luogu.org/blog/zjp-shadow/cheng-fa-ni-yuan
1 #include<cstdio> 2 using namespace std; 3 4 int inv[3000030],p; 5 6 int main(){ 7 int n,p; 8 scanf("%d%d",&n,&p);printf("1 ");inv[1]=1; 9 for(int i=2;i<=n;i++){ 10 inv[i]=(-1LL*(p/i)*(inv[p%i]))%p; 11 inv[i]=((inv[i]%p)+p)%p; 12 printf("%d ",inv[i]); 13 } 14 }