线性求逆元

xiaoxiao2021-02-28  8

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

转载请注明原文地址: https://www.6miu.com/read-200350.html

最新回复(0)