线性求逆元

来源:互联网 发布:淘宝新店发布宝贝 编辑:程序博客网 时间:2024/06/07 21:38

mod为质数。

#include <iostream>using namespace std;const int N = 10000005;const int mod = 1e9+7;int inv[N];void init(){    inv[1] = 1;    for(int i=2; i<N; i++)    {        if(i >= mod) break;        inv[i] = (mod - mod / i) * inv[mod % i] % mod;    }}int main(){    init();    for(int i = 1; i <= 10; ++i)        cout << (inv[i]%mod+mod)%mod << endl;    return 0;}

参考:http://blog.csdn.net/acdreamers/article/details/8220787

http://blog.csdn.net/outer_form/article/details/51509360

https://www.cnblogs.com/Phantom01/p/3939759.html

原创粉丝点击