【题解】洛谷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-10-04
  • 2021-08-09
  • 2019-08-07
  • 2022-01-16
  • 2021-11-17
  • 2019-08-19
  • 2021-12-03
猜你喜欢
  • 2018-07-30
  • 2021-01-02
  • 2019-05-22
  • 2019-07-21
  • 2021-11-19
  • 2019-07-23
相关资源
相似解决方案