Basic Topic 8 of number theory [Euclidean] [sieve prime number] [Chinese Remainder Theorem]

Source: Internet
Author: User

I have read the number theory knowledge before. Now I want to find some questions .....


Poj 1061 Portal

Here, we will give you X, Y, M, N, and L. Represents the coordinate X of frog a, y of frog B, m of frog a, n of frog B, and mod value L, find the number of encounter hops. (M-N) * X0 = (x-y) (mod L); the solution of the modulus linear equation, but pay attention to the processing, because (m-N) and (x-y) may be negative. If (m-N) is negative, a negative number is directly obtained for the two numbers. The following is a pair (x-y) + l) % L.

Then you can use the modular_linear_equation (ll a, LL B, ll N) function.

Code


Poj 2142 Portal

Given that Abd is three weights, AB is known weights, and now requires D, that is, M * A + N * B = d to obtain ABS (m) + for the maximum value of ABS (N), we first use the modular_linear_equation (ll a, LL B, ll N) function to obtain a set of special solutions. When M or N is the smallest, obtain the N or M of the response, and find that the minimum value of the two groups is a small value.

Code


Poj 2689 Portal

Detailed description


Poj 2262 Portal

The question is as follows: Any even number can be written as the sum of two prime numbers. Here, we will give you a number less than W. C will help you find the combination a + B = C, requiring a to be as small as possible, B is as big as possible.

For million data, a prime number table is used directly.


Poj 1006 portal poj 2891 Portal

For more information about the Chinese Remainder Theorem, see my blog.


HDU 1222 Portal

Question

Give M and N. A number is 0, M is added each time, and mod n is used to ask if 0 ~ N-1.

That is, to list the equation A * x = B (mod n) When B is 0, 1, 2, 3, 4 .... whether there is a solution in N-1 is actually an idea. Let's first look at the Extended Euclidean Algorithm:

// Ax = B (mod n) bool modular_linear_equation (ll a, LL B, ll N) {ll X, Y, x0, I; ll d = ex_gcd (A, N, x, Y); If (B % d! = 0) return false; X0 = x * (B/d) % N; // Special Solution for (I = 1; I <D; I ++) // The number of solutions is d printf ("% d \ n", (x0 + I * (N/D) % N); Return true ;}
In fact, when gcd (A * X, N)/B! When the value is 0, there is no solution B (0, 1, 2, 3, 4,..., n-1), that is, there is no solution when gcd (A, n) = 1.


HDU 1576 portal question: Portal

Give N, B, (n = A % 9973), and find the value of (a/B) % 9973.

N = A-A/9973*9973, A = Bx, Bx-A/9973*9973 = n. That is, Bx-9973y = n. Finally, obtain the value of X % 9973.

Extended Euclidean, bare question, if said the difficulty lies in the previous structure.






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.