当前位置:网站首页>P3811 [template] multiplicative inverse

P3811 [template] multiplicative inverse

2022-06-11 07:09:00 qq_ forty-six million five hundred and eighty thousand two hund

P3811 【 Templates 】 Multiplicative inverse element
O(n) seek 1~n Inverse element

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,p;
int inv[3000005];
int main()
{
    
    scanf("%d%d",&n,&p);
    inv[1]=1;
    printf("1\n");
    for(int i=2;i<=n;i++)
    {
    
        inv[i]=1ll*(p-p/i)*inv[p%i]%p;
        printf("%d\n",inv[i]);
    }
    return 0;
}
原网站

版权声明
本文为[qq_ forty-six million five hundred and eighty thousand two hund]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203020523406711.html