【题解】洛谷P3811【模板】乘法逆元


#include<cstdio>
const int N=3e6+10;
int inv[N];
int main()
{
	int n,p;scanf("%d%d",&n,&p);
    inv[1]=1;
    for(int i=2;i<=n;i++)
        inv[i]=1ll*(p-p/i)*inv[p%i]%p;
    for(int i=1;i<=n;i++)
        printf("%d\n",inv[i]);
    return 0;
}

总结

补一个线性递推逆元的模板。以后注意凡是有乘法都开long long

相关文章:

  • 2021-08-16
  • 2021-07-06
  • 2021-10-23
  • 2021-12-07
  • 2021-06-24
  • 2021-11-06
  • 2022-12-23
猜你喜欢
  • 2021-08-07
  • 2021-08-10
  • 2022-01-13
  • 2021-10-27
  • 2021-12-26
  • 2021-10-07
相关资源
相似解决方案