The cost of the study of number theory and Euler

Source: Internet
Author: User

Review of number theory and the cost of the horse and Euler

QB_UDG years One Month 8 Day 10:16:18

1. Fermat theorem Fermat theory

if P is prime , and a with the P coprime, i.e. gcd (a,p) =1 so (a^p-1) ≡1 (mod p)

application : solving multiplication inverse element

multiplication Inverse element : (x*x ') ≡ 1 (mod p) called X ' is the multiplication inverse of the X-mode P (note that it must be 1)

Inverse: (b/a) (mod n) = (b * x) (mod n). x represents the inverse of a. and a*x≡1 (mod n) Note: The inverse is only present when A and n coprime

Note that the inverse can also be understood, to find a minimum positive integer x (inverse), so that a Times x to M of the remainder equal to 1 m of the remainder, so m=1, the inverse is 1

Because (a^p-1) ≡1 (mod p) then (a*a^p-2) ≡1 (mod p)
So a^p-2 is a multiplicative inverse of modulo p .

Use of inverse element:

When solving the division modulo problem (A/b)%m, we can convert to (a% (b?m))/b,
However, if B is large, there will be a burst accuracy problem, so we avoid using division to calculate directly.
You can convert a division to a multiplication by using an inverse element:
Suppose B has a multiplicative inverse, that is, with M coprime (sufficient and necessary). Set C is the inverse of B, i.e. b?c≡1 (mod m), then there is a/b= (A/b)?1<=> (A/b)? B?cóa?c (mod m)
That is, dividing by a number modulo equals the inverse modulo of the number.

So (A/b) mod p is converted to (a*b ') mod p = ((a mod p) * (b^p-2 modp)) mod p

Applies to p as prime number

2. Euler functions
for a positive integer x , less than x and and the x coprime of the positive integers of the number , remember to do: φ (x)
where φ (1) is defined as 1, but does not have any real meaning

General Formula 1:φ (x) =x* (1-1/P1)(1-1/p2) (1-1/p3) ..... (1-1/PN)
Where P1,P2,P3......PN is all the mass factor of X

General Formula 2: if x is the k Power of prime number P , i.e. x=p^k, with φ (x) = p^k-p^ (k-1) = (p-1) *p^ (k-1)
Because the quality factor of X is only p, so in addition to multiples of p, the other numbers are coprime with X. (In the program we generally write φ (x) as Phi (X)).

Properties:

1. If x, y coprime (i.e. gcd (x, y) =1), then φ (x*y) =φ (x) *φ (y)
2. If x is odd φ (2x) =φ (x)
3. If x is prime number φ (x) =x-1
4. if x>2,φ (x) is even

The above four can be launched according to Euler function! And obviously!

3. Euler's theorem

If the a,n is a positive integer and a,n coprime (that is, gcd (a,n) =1), then there are:

A^φ (n) ≡1 (mod n)

According to this theorem, the Fermat theorem is obviously, because the Phi (p) of prime number p is equal to P-1

Application:

Power down!

A and n coprime, when B is large, the Euler theorem can be used to power down

(a^b) mod n = (a^ (Bmod Phi (n))) mod n

Finally, how do you find Phi (p)?

See Euler screens :

The following properties are required ( p is prime ):
Phi (P) =p-1
Because the prime number p except 1 is only p, so the integer 1 to p is only p and p not coprime


If I mod p = 0, then phi (i * p) =p * PHI (i)
If the integer n is not with I coprime, n+i remains with I not coprime
If the integer n with i coprime, n+i and I remain coprime, proving that:


If I modp≠0, then Phi (i * p) =phi (i) * (p-1)
I mod p is not 0 and P is prime, so I and P coprime, then according to the Euler function of the product phi (I * p) =phi (i) * PHI (P) where Phi (p) =p-1 is the first property

#include<iostream>
#include<cstdio>
#DefineN 40000
using namespaceStd
intN
intPhi[n+10],prime[n+10],tot,ans;
BOOLMARK[N+10];
void Getphi()
{
intI,j;
Phi[1]=1;
for(i=2;i<=n;i++)//equivalent to decomposition of the inverse process of the mass-type
{
if(!mark[i])
{
prime[++tot]=i;//the number of sieve primes first determines whether I is a prime number.
phi[i]=i-1;//When I is a prime number phi[i]=i-1
}
for(j=1;j<=tot;j++)
{
if(i*prime[j]>n) Break;
mark[i*prime[j]]=1;//OK I*prime[j] not prime
if(i%prime[j]==0)//Then we will see if PRIME[J] is an approximate of I
{
PHI[I*PRIME[J]]=PHI[I]*PRIME[J]; Break;
}
Elsephi[i*prime[j]]=phi[i]* (prime[j]-1);//actually here prime[j]-1 is phi[prime[j]], using the product of Euler function
}
}
}
int Main()
{
Getphi ();
}

To summarize:
Plainly, dividing by a number modulo, the inverse modulo effect is the same as multiplying the number.
The inverse is actually the a*x = 1 (mod C) set up X, where a is the divisor of division (seemingly also pull to expand,,)

To solve the problem (A/b)%m, we can turn to (a*b ') mod m to resolve, where B ' is the inverse of B

Power Down,
A and n coprime, when B is large, the Euler theorem can be used to power down

(a^b) mod n = (a^ (Bmod Phi (n))) mod n

The cost of the study of number theory and Euler

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.