Obtain the prime number by using the screening method of the unique factorization theorem of ultraviolet A 10375. [number theory]
The basic content of the unique decomposition theory:
Any positive integer greater than 1 can represent the product of several prime numbers, and the representation method is unique. In other words, a number can be uniquely divided into the product of a prime factor. Therefore, this theorem is also called the unique decomposition theorem.
Example: 50 = (2 ^ 1) * (5 ^ 2)
The general idea of the question is to create a prime number table. e = {, 0, 0 ......}
The following are two questions. Let's just talk about the general idea:
Question 1:
E = (X1 * X3 * X4 *... * Xk)/X2 judge whether E is an integer
If you set (X1 * X3 * X4 *... * Xk) is divided into prime numbers, and X2 is also divided into prime numbers, if (X1 * X3 * X4 *... * Xk) If X2 can be divisible, then the exponent of each prime number must be (X1 * X3 * X4 *... * Xk) is larger than X2. If one is smaller than X2, it indicates that it is not an integer.
Question 2:
Known C (m, n) = m! /(N! (M-n !)), Input integer p, q, r, s, (p> = q, r> = s, pqrs <10000), calculate C (p, q)/C (r, s), the output must not exceed 10 ^ 8, and keep the five decimal places.
The first time I saw this question, I had no idea. After I learned the unique decomposition theory, I had some ideas,
Let's think about this question: we set C (p, q)/C (r, s) = (p! * S! * (R-s )!) /(Q! * (P-q )! * R !)
C (p, q)/C (r, s) = [p * (p-1)... (p-q + 1) * s! ]/[R * (r-1)... (r-s + 1) * q! ]
However, it is not possible to multiply all the numbers and then divide the numbers into quality factors and the number of qualitative factors in the numerator increases, number of quality factors decomposed by denominator is reduced
Finally, check all the quality factors. If the number is positive and the number is negative, Division is required.
So how should we write it? Based on the above knowledge, we should easily understand our thoughts .......
The following garbage code is attached:
# Include
# Include
# Include
# Include
# Include
Using namespace std; # define maxn 10005int e [maxn];/** e Represents the prime coefficient of each prime number representing {2, 3, 5, 7, 11 ......} * // ** if the vis array is marked as 0, it indicates the prime number */int vis [maxn]; void getPrimevis (int n) {int m = sqrt (n + 0.5 ); memset (vis, 0, sizeof (vis); for (int I = 2; I <= m; I ++) for (int j = I * I; j <= n; j + = I) vis [j] = 1;}/** prime array: prime [] = {2, 3, 5, 7, 11, 13 ......} */vector
Prime; void getprimeprime (int n) {for (int I = 2; I <= n; I ++) if (vis [I] = 0) prime. push_back (I);} // change n to a prime number and exist in the e array. Perform the addition and subtraction operation void add_integer (int n, int d) on the e array) {for (int I = 0; I
> P> q> r> s) {memset (e, 0, sizeof (e); add_factorial (p, 1); add_factorial (q,-1 ); add_factorial (p-q,-1); add_factorial (r,-1); add_factorial (s, 1); add_factorial (r-s, 1); double ans = 1; for (int I = 0; I