Various inverse elements

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.