1012: Diophantus was a Greek, not a geek.
| Result | TIME Limit | MEMORY Limit | Run Times | AC Times | JUDGE |
|---|---|---|---|---|---|
| 3s | 8192K | 4695 | 1754 | Standard |
An equation of the form ax + by = c is a Diophantine equation, where a, b, and c are positive integers.
Such an equation has no integer solution if the greatest common divisor of a and b does not divide c. If it does divide c, then a solution exists.
The greatest common divisor (gcd) of two positive integers, is the largest integer that divides both a and b. For example, the gcd of 2 and 6 is 2. The gcd of 9 and 12 is 3. The gcd of 15 and 7 is 1.
Given a diophantine equation, determine if it has any solutions.
Input
A positive integer, denoting the number of equations.
A diophantine equation. Each equation will be of the form: <num>x+<num>y=<num>, where <num> denotes a positive integer(<=65536). Each equation will be on a separate line and will contain no blanks.
Output
The phrase “<equation> has a solution.” if a solution exists, or the phrase “<equation> has no solution.” if one does not exist, where <equation> is the equation in question.
Sample Input
2 2x+5y=11 60x+18y=97
Sample Output
2x+5y=11 has a solution. 60x+18y=97 has no solution.
This problem is used for contest: 53
Submit / Problem List / Status / Discuss
This program checks if a Diophantine equation of the form ax + by = c has integer solutions. It computes the greatest common divisor (gcd) using Euclidean algorithm and verifies if the gcd divides the constant term c. The program reads input equations and outputs whether they have a solution or not.
148

被折叠的 条评论
为什么被折叠?



