Some of the properties of the supplementary explanation of the number theory division:
(1) can be 2 The number of integers, the number on the single digit, can be 2 divisible
() can be 4 The number of divisible digits, the two-digit number of bits and 10 digits can be 4 divisible
(*) can be 8 The number of divisible numbers, the hundred, 10 digits, and the three digits of a digit can be 8 divisible
(4) can be 5 the number of evenly divisible, at the end is 0 or 5
(5*) can be - The number of divisible numbers, 10-bit and single-digit two-digit can be - divisible
(6*) can be the The number of divisible numbers, the hundred, 10 digits, and the three digits of a digit can be the divisible
(7) can be 3 The sum of the numbers on each digit can be 3 divisible
(8*) can be 9 The number of integers, the numbers on each digit and the number of digits that can be 9 divisible
(9) If a number can be 2 divisible and can be 3 divisible, then this number can be 6 divisible
(10) If a number can be 2 divisible and can be 5 divisible, then this number can be Ten divisible (that is, the digits are 0 )
(11*) can be One The number of integers, the number on the odd digit (from left to right) and the number on the even digits and the difference (the large number of decreases) can be One divisible
of decimalsGCD:
EPS control precision,fmod is C + + library function, operation floating point number of the mod operation.
To expand Euclid:
Ps: about Euclid and expand Euclid can refer to my other blog post " Euclid & Expand Euclid Algorithm Explanation (Euclid & extend-euclid algorithm)"
( 1 ) solving indefinite equations:
The so-called indefinite equation, that is, the number of unknowns is more than the number of equations, and the unknown is limited by some (such as the requirement is a rational number, integer or positive integer, etc.) of the equation or equation set.
As 3x-4y==6, the equation has only one, but the solution can have multiple.
To solve a set of solutions to an indefinite equation, or to determine whether an indefinite equation has a solution, the expansion of Euclid can be useful.
(2) solving linear linear equations (congruence):
Solve ax≡b (mod P), the smallest solution of unknown X.
(3) The inverse element of the solution module:
The congruence equation ax≡b (mod n), if gcd (a,n) = =1, the equation has only the unique solution. In this case, if b==1, the congruence equation is ax ≡ 1 (mod n), gcd (a,n) =1. at this point the X is calculated as the inverse of the modulo n multiplication of a.
PS: On the inverse, there is a pretty useful property:
Set P to Prime,(A/b)% P = A * b^ (p-2)% p , so that the division can be treated as a multiplication.
Prime number: Definition
The prime number is a positive integer greater than 1 , and it cannot be divisible by other positive integers except 1.
Non-primes are called composite.
Eratosthenes Sieve method of prime number
Sieve method is a more important algorithm in number theory, in O (sqrt (N)) time to obtain All the prime number within N.
The so-called Sieve method, is the number of each sieve. , the starting all the number is marked as prime, when encountering 2 , all the multiples of 2 are marked as composite, and so on, the rest is the prime number.
The algorithm is suitable for smaller MAXN, and for larger MAXN, memory can not open such a large space.
Interval prime
the prime number of the [L, U] interval is obtained, andl and u are large, but the u-l is not very large.
First, linearly sift out all the primes between 1 and sqrt (2147483647) ( what is 2147483647? Guess to yourself ), and then the prime number of the given interval is sifted out by the prime number of the sun.
It's a template, no code here ~
Trial Division of Prime number determination
Is the simple algorithm that everyone will, with less than the number of all primes to try to divide, if not divisible, then the prime, the complexity O (sqrt (N)).
miller-robin random primality test
About the miller-robin algorithm, you can split another chapter to explain, so here only to do a brief introduction.
Miller-rober with randomness, it is possible to measure the pseudo prime, the probability is 1/(2^s), the general s is about,
Thus, the probability of error is very low, and it is suitable for large number primality judgment.
About the time complexity of Miller-robin, the worst is (1+o (1)) *log2 (N). Miller-rabin the performance of the algorithm is very good. In practical applications, The actual execution speed of Miller-rabin is also very fast.
The only decomposition theory
Definition: the natural number n can be expressed as the product of primes
Some conclusions:
①, approximately several numbers of N, for (x1+1) * (x2+1) *......* (xm+1)
Decomposition of mass factor common decomposition factorization
N is decomposed into a mass factor, the decomposition factor is deposited into the array FACs , and the length is cnt.
First, find a minimum prime number K;
If the prime number equals n, the process of decomposing the mass factor is over;
If n>k, and k|n, then record k,n/=k, and then continue to look for;
If n cannot be divisible by k ,k+=2, continue to seek.
Pollard_rhoFactor decomposition
It is suitable for the decomposition mass factor of large number, and the returned mass factor is disordered.
The Chinese remainder theorem of Euler function
Resources:
①, Elementary explanation of the theory of number in Northeast Normal University
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
A supplementary explanation of the basis of number theory