Various inverse elements
Tags: mathematical methods-Number theory
Reading experience: https://zybuluo.com/Junlier/note/1300025
Copyright notice: Part of the knowledge collected in the book, "Mathematics a Pass" (definition ah What)
Fermat theorem
When \ (p\) is prime ,\ (x\) is the inverse of \ (X^{p-2}\mod p\)
Of course, it can't be that simple and cheap.
So there is a limit : Only P is a prime number and can be used
Extended Euclid\ (exgcd\)
\ (exgcd\) is a set of special solutions for \ (AX+BY=GCD (b) \)
Due to the definition of the inverse element:
If \ (a*x \equiv1 (\mod b) \) , then \ (x\) is the inverse of \ (a\)
This formula can also be transformed into:\ (ax+by=1\) ...
This is what \ (exgcd\) can do spicy (obviously \ (a,b\) coprime)
Then put another \ (exgcd\) of the board (the total hit wrong ... )
lst Exgcd(lst a,lst b,lst &x,lst &y){ if(!b){x=1,y=0;return a;} lst ss=Exgcd(b,a%b,x,y),t; t=x,x=y,y=t-a/b*y; return ss;}//直接背板子然后直接用,返回的值ss是a和b的GCD//反正特解在x里面了就行了。。。一些题目也可以好好运用这个GCD。。。
\ (exgcd\) template title: luoguP1082 [Noip2012] congruence equation
Linear recursive derivation of inverse element
Just take it down, I'm not going to prove it.
Perceptual Understanding:\[inv[i]=p-(p/i*inv[p\%i]) \%p\] go online Baidu prove it
I suddenly found this article very short.
So what... Afterward
Various inverse elements