P3811 【模板】乘法逆元
线性递推逆元模板
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #define re register 5 using namespace std; 6 int n,p,inv[3000002]; 7 int main(){ 8 scanf("%d%d",&n,&p); inv[1]=1; puts("1"); 9 for(re int i=2;i<=n;++i){ 10 inv[i]=1ll*(p-p/i)*inv[p%i]%p; 11 printf("%d\n",inv[i]); 12 }return 0; 13 }