MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / diophantine

Function diophantine

blockchain/diophantine_equation.py:6–30  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

4
5
6def 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
33def diophantine_all_soln(a: int, b: int, c: int, n: int = 2) -> None:

Callers 1

diophantine_all_solnFunction · 0.85

Calls 2

greatest_common_divisorFunction · 0.90
extended_gcdFunction · 0.70

Tested by

no test coverage detected