Getting a brief summary of Number Theory

$ Umm $ because $ gql $ number theory too bad, so I decided to summarize some of the more basic knowledge of number theory, and are not familiar with what may prove somewhat of $ QwQ $

$gcd\ \&\ exgcd$

Aung $ gcd $'re through it, proved to be too obviously I will not say $ kk $

Too lazy to put the code can go to $ exgcd $ code, when do $! B $ when $ a $ that is the answer to $ QwQ $

$ Exgcd $ Solutions for the form $ a \ cdot x + b \ cdot y = c $ equation

First on a conclusion, this equation has a solution if and only if $ gcd (a, b) |. C $ Ang Pei Shu Theorem this is too lazy to permit anyway respectively from both necessary and sufficient evidence like $ QwQ $.

Then I probably $ exgcd $ certification process lie under $ QwQ $

Let me talk, I'm here syndrome $ a \ cdot x + b \ cdot y = gcd (a, b) $, then $ c = k for the case cdot gcd (a, b) $ complete solution directly \ multiplied by $ Well k $'d be $ QwQ $

  • When $ b = 0 $ when $ gcd (a, b) = a $, at this time there is a set of integer solutions apparently $ x = 1, y = 0 $
  • When $ b \ neq 0 $, by the Euclid theorem $ gcd (a, b) = gcd (b, a \ mod \ b) $.

所以有$a\cdot x_1+b\cdot y_1=gcd(a,b)=gcd(b,a\ \%\ b)=b\cdot x_2+(a\ \%\ b)\cdot y_2$

And because $ a \ mod \ b = a- \ lfloor \ frac {a} {b} \ rfloor \ cdot b $

带入得$a\cdot x_1+b\cdot y_1=b\cdot x_2+(a-\lfloor \frac{a}{b}\rfloor\cdot b)\cdot y_2$

变形得$a\cdot x_1+b\cdot y_1=b\cdot x_2+a\cdot y_2-\lfloor \frac{a}{b}\rfloor\cdot b\cdot y_2$

    $a\cdot x_1+b\cdot y_1=a\cdot y_2+b\cdot(x_2-\lfloor \frac{a}{b}\rfloor\cdot y_2)$

It is $ x_1 = y_2, y_1 = x_2- \ lfloor \ frac {a} {b} \ rfloor \ cdot y_2 $

Common applications then it should be solving inverse? That is when the divisor and the modulus is not relatively prime to $ solved by $ exgcd.

$ exgcd $ board $ code $

Euler's theorem & Extended Euler's theorem

Aung first put conclusions again proved to lie $ QwQ $

Euler's theorem: $ \ forall \ gcd (a, n) = 1, a ^ {\ phi (n)} \ equiv \ 1 (mod \ n) $ $ n-$ when a prime number which Fermat's little theorem. $ QwQ $

Extended Euler's theorem: $ a ^ b \ equiv \ begin {cases} a ^ (b \ mod \ \ phi (n)) & \ gcd (a, b) = 1 \\ a ^ b & \ gcd (a, n) \ neq 1, b <\ phi (n) (mod \ n) \\ a ^ {(b \ mod \ \ phi (n)) + \ phi (n)} & \ gcd (a, n) \ neq 1, b \ geq \ phi (m) (mod \ n) \ end {cases} $

Euler's theorem:

Provided with n-$ $ prime number $ x_1, x_2, ..., x _ {\ phi (n)} $

Because $ gcd (a, n) = 1 $

It is $ a \ cdot x_1, a \ cdot x_2, a \ cdot x_3, ..., a \ cdot x _ {\ phi (n)} $ are coprime with n-$ $ differ from each other

Therefore $ x_1, x_2, ..., x _ {\ phi (n)} $ and $ a \ cdot x_1, a \ cdot x_2, a \ cdot x_3, ..., a \ cdot x _ {\ phi (n) } $ certain correspondence

于是有$a\cdot x_1\cdot a\cdot x_2\cdot ...\cdot a\cdot  x_{\phi(n)}\equiv x_1\cdot x_2\cdot ...\cdot x_{\phi(n)}(mod\ n)$

整理得$a^{\phi(n)}\cdot \prod x_{i}=\prod x_{i}(mod\ n)$,$(a^{\phi(n)}-1)\cdot \prod x_{i}=0(mod\ n)$

And because all of the $ x $ relatively prime to $ n $, is proved!

Expand Euler's theorem:

Three were lying on the certificate under $ QwQ $

$case\ 1:$

Provided $ b = k \ cdot \ phi (n) + c $.

于是有$a^b\equiv a^{k\cdot \phi(n)+c}\equiv a^{k\cdot \phi(n)}\cdot a^c\equiv a^c\equiv a^(b\ mod\ \phi(n))$

$case\ 2:$

$ Umm $ permit this thing to $ QwQ $

$case\ 3:$

Let me talk a little conclusions $ QwQ $

After considering the prime factorization of $ A $ is $ a = d_1 ^ {p_1} \ cdot d_2 ^ {p_2} \ cdot ... $, if card $ \ forall d $ satisfy $ d ^ b \ equiv d ^ { (b \ \% \ \ phi (n)) + \ phi (n)} (mod \ n) $, can permit $ a ^ b \ equiv a ^ {(b \ \% \ \ phi (n)) + \ Phi (n-)} (MOD \ n-) $.

Proband this conclusion lie $ QwQ $

Consider Ruoyi card $ \ $ FORALL D satisfies D ^ B $ \ equiv {D ^ (B \ \% \ \ Phi (n-)) + \ Phi (n-)} (MOD \ n-) $

There $ (D ^ {P}) ^ B \ equiv (D ^ {P}) ^ {(B \ \% \ \ Phi (n-)) + \ Phi (n-)} (MOD \ n-) $

于是有$(d_1^{p_1}\cdot d_2^{p_2}\cdot ...)^b\equiv (d_1^{p_1}\cdot d_2^{p_2}\cdot ...)^{(b\ \%\ \phi(n))+\phi(n)}(mod\ n)$,即$a^b\equiv a^{(b\ \%\ \phi(n))+\phi(n)}(mod\ n)$.

欧克于是接下来就只用证$d^b\equiv d^{(b\ \%\ \phi(n))+\phi(n)}(mod\ n)$

1)若$gcd(d,n)=1$.

由$case\ 1$得显然成立.

2)若$gcd(d,n)\neq 1$

令$n=s\cdot d^r,gcd(s,d)=1$

于是有$d^{\phi(s)}\equiv 1(mod\ s)$,又因为$gcd(s,d)=1$,于是有$\phi(s)|\phi(n)$,于是有$p^{\phi(n)}\equiv 1(mod\ s)$

变形得$d^{\phi(n)+r}\equiv d^r(mod\ n)$

于是有$d^b\equiv d^{b+\phi(n)}(mod\ n)$

于是发现每次指数相差$\phi(n)$依然是成立的,于是有$d^b\equiv d^{(b\ mod\ \phi(n))+\phi(n)}(mod\ n)$,得证$QwQ$

应用的话一个是在$mod$为质数时常用欧拉定理.还一个就求指数幂的时候不用担心指数爆炸了$QwQ$

逆元

$umm$只写下线性递推的了$QwQ$还有两种一个是$exgcd$,还一种是欧拉定理快速幂,前面都写了$QwQ$

先放结论趴,若模数为$m$,有$inv_i=((m-\lfloor\frac{m}{i}\rfloor)\cdot inv_{m\%i})\ mod\ m$

设$t=\lfloor\frac{m}{i}\rfloor,k=m\%i$.

显然$t\cdot i+k\equiv 0(mod\ m)$,于是有$-t\cdot i\equiv k(mod\ m)$,于是有$-t\cdot inv_k\equiv inv_i(mod\ m)$

于是有$inv_i=-\lfloor\frac{m}{i}\rfloor\cdot inv_{m\%i}$,两边同加$m\cdot inv_{m\%i}$显然无影响,于是有$inv_i=((m-\lfloor\frac{m}{i}\rfloor)\cdot inv_{m\%i})\ mod\ m$

板子 $code$

质因数分解

$umm$只是$mk$一个小技巧$QwQ$.

就可以先预处理出每个数最大的质因数(其实随便一个质因数都成没影响的$QwQ$.

然后每次分解质因数的时候就能直接做下去,复杂度似乎是$O(logn)$的$QwQ$

$crt\ \&\ excrt$

$umm$我之后的所有知识点都先写内容再写证明好了$QwQ$

$CRT:$

设$m_1,m_2,...,m_n$两两互质,则对于方程组$x\equiv a_i(mod\ m_i)$,在$\prod m_i$范围内有唯一解.

设$M=\prod m_i,p_i=\frac{M}{m_i},q_i\equiv \frac{1}{p_i}(mod\ m_i)$

于是有$as=\sum a_i\cdot q_i\cdot p_i$

$exCRT:$

不保证$m_i$之间两两互质.(这个其实还$easy$些$QwQ$?

考虑若$n=2$,也就$x\equiv a_1(mod\ m_1),x\equiv a_2(mod\ m_2)$

变形得$x=m_1\cdot x_1+a_1=m_2\cdot x_2+a_2

$就只要解出一个$m_1\cdot x_1-m_2\cdot x_2=a_2-a_1$的使得$x$最小的解就成,所以就$exgcd$解下呗$QwQ$.

设解出的$x$为${x}'$,于是原式变为,$x\equiv {x}'(mod\ lcm(m_1,m_2))$

这么一直做下去就好$QwQ$

证明:

$crt:$

只证充分性了$QwQ$

考虑因为$m_i$之间两两互质,所以对于$j\neq i$,$q_i\ mod m_j\equiv 0$,也就说对每个$i$,$\sum a_i\cdot q_i\cdot p_i$在膜$m_j$下有意义的只有$a_j\cdot q_j\cdot p_j$,又因为$q_j\cdot p_j\equiv 1(mod\ m_j)$

于是显然$QwQ$

$excrt:$

$umm$话说我$jio$得我前面港做法的时候就把证明差不多搞完了?不说了$QwQ$

说下应用趴,$crt$一般用于题目模数不是质数时的合并.即,若一个模数唯一分解$m=\prod p_i^{a_i}$,那么我们解出所有在$mod\ p_i^{a_i}$意义下的解然后合并就好

$CRT$板子 $code$

$exCRT$板子 $code$

$BSGS\ \&\ exBSGS$

一般用于求解形如$a^x\equiv b(mod\ p)$的方程.其中$BSGS$有限制:$gcd(a,p)=1$,$exBSGS$没有这个限制

因为这不是什么定理所以就不是以内容+证明的形式了,直接写怎么做,正确性其实就在里面了$QwQ$

先说$BSGS$趴

考虑将设$tmp=\left \lfloor \sqrt{mod} \right \rfloor$,$x=i*tmp+j$

然后式子就可以变形成, $ a^{i \cdot tmp} \equiv b \cdot a^{j} $

然后预处理出右边的值存到$map$中,枚举左边查就行$QwQ$.复杂度就$O(\sqrt(p))$

然后港下$exBSGS$.

设$d=gcd(a,p)$.

先将原式变形得$a^x+p\cdot k=b$.

于是两边同除$d$得$\frac{a}{d}\cdot a^{x-1}+\frac{p}{d}\cdot k=\frac{b}{d}$.这样就可以当作$\frac{a}{d}$是一个系数了

然后一直做下去直到$gcd(a,\frac{p}{d})=1$,这时候就又成$BSGS$了,把系数除去后跑个$BSGS$最后再还原回去就好$QwQ$

另外,如果过程中$\frac{b}{d}$不是整数了,就说明无解,$over$

$BSGS$板子 $code$

$exBSGS$板子

组合数学

这个我可能有时间会另外开坑,,,只是$mk$下$QwQ$

莫比乌斯反演

同上$w$

博弈论

同上$w$

二次剩余

咕咕

$miller-rabin$

咕咕

$pollard-rho$

咕咕

同余类最短路

咕咕

原根

Guess you like

Origin www.cnblogs.com/lqsukida/p/11587477.html