Zoj 2678 bishops on a Toral board homogeneous equations, complete system (3-I)

Source: Internet
Author: User

Question address: http://acm.zju.edu.cn/onlinejudge/showProblem.do? Problemcode = 2678.

Question: 1 the answer to this question is gcd (m, n)

2. The point on the board is (I, j) 0 <= I <= s-1; 0 <= j <= n-1; from (a, B) the point at which the K step is reached is (a + k) % m, (B + k) % N) the problem now is, at least how many integer pairs are needed

(A, B) forms a point set, making it possible for any I, j, 0 <= I <= s-1; 0 <= j <= n-1; A (A0, B0) and an integer k must exist in this vertex set.

(A0 + k) % m, (b0 + k) % n) = (I, j)

This is a problem of homogeneous equations. It can be proved in number theory that the necessary and sufficient conditions for the solution of X = a (mod m) and X = B (mod n) are (m, n) | (a-B)

In this question, we must (m, n) | j-I-(B-)

3. The adequacy and necessity indicate that the elements of the point set are (m, n );

Adequacy: only (m, n) points are required. (M, n) points: (0, Y) 0 <= Y <= (M. n)-1; The "B-a" composed of such points can traverse the complete series of MOD (m, n), so no matter whether J-I is in mod (m, n) we can take out all the values in the system, so that we can remove them.

Necessity: less than (m, n) elements do not work: once the number of points is less than (m, n) then the value of "B-a" will be less (because it may be repeated), that is to say, B-A cannot take the complete series of MOD (m, n.

Obviously, J-I can be traversed (Set M <= n to make I = 0, and J motion is acceptable), regardless of how (I, j) all of them have B-a to satisfy the conflicts between them.

In summary, the number of elements in the smallest point set is (m, n)

import java.math.*;import java.util.*;import java.io.*;public class Main {    public static void main(String[] args) throws Exception {  Scanner cin=new Scanner(System.in);    boolean first=true;  while(cin.hasNext())     { if(first==false)  System.out.println(); if(first==true)  first=false;  BigInteger m=cin.nextBigInteger(); BigInteger n=cin.nextBigInteger();  System.out.println(m.gcd(n));  }         }         }     

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.