Diophantine Equation : Given integers a,b,c ( at least one of a and b != 0), the diophantine equation a*x + b*y = c has a solution (where x and y are integers) iff greatest_common_divisor(a,b) divides c. GCD ( Greatest Common Divisor ) or HCF ( Highest Common Factor ) >>> diop
(a: int, b: int, c: int)
| 4 | |
| 5 | |
| 6 | def diophantine(a: int, b: int, c: int) -> tuple[float, float]: |
| 7 | """ |
| 8 | Diophantine Equation : Given integers a,b,c ( at least one of a and b != 0), the |
| 9 | diophantine equation a*x + b*y = c has a solution (where x and y are integers) |
| 10 | iff greatest_common_divisor(a,b) divides c. |
| 11 | |
| 12 | GCD ( Greatest Common Divisor ) or HCF ( Highest Common Factor ) |
| 13 | |
| 14 | >>> diophantine(10,6,14) |
| 15 | (-7.0, 14.0) |
| 16 | |
| 17 | >>> diophantine(391,299,-69) |
| 18 | (9.0, -12.0) |
| 19 | |
| 20 | But above equation has one more solution i.e., x = -4, y = 5. |
| 21 | That's why we need diophantine all solution function. |
| 22 | |
| 23 | """ |
| 24 | |
| 25 | assert ( |
| 26 | c % greatest_common_divisor(a, b) == 0 |
| 27 | ) # greatest_common_divisor(a,b) is in maths directory |
| 28 | (d, x, y) = extended_gcd(a, b) # extended_gcd(a,b) function implemented below |
| 29 | r = c / d |
| 30 | return (r * x, r * y) |
| 31 | |
| 32 | |
| 33 | def diophantine_all_soln(a: int, b: int, c: int, n: int = 2) -> None: |
no test coverage detected