1
- # Diophantine Equation : Given integers a,b,c ( at least one of a and b != 0), the diophantine equation
2
- # a*x + b*y = c has a solution (where x and y are integers) iff gcd(a,b) divides c.
1
+ # Diophantine Equation : Given integers a,b,c ( at least one of a and b != 0), the
2
+ # diophantine equation a*x + b*y = c has a solution (where x and y are integers)
3
+ # iff gcd(a,b) divides c.
3
4
4
5
# GCD ( Greatest Common Divisor ) or HCF ( Highest Common Factor )
5
6
@@ -29,8 +30,9 @@ def diophantine(a, b, c):
29
30
30
31
# Finding All solutions of Diophantine Equations:
31
32
32
- # Theorem : Let gcd(a,b) = d, a = d*p, b = d*q. If (x0,y0) is a solution of Diophantine Equation a*x + b*y = c.
33
- # a*x0 + b*y0 = c, then all the solutions have the form a(x0 + t*q) + b(y0 - t*p) = c, where t is an arbitrary integer.
33
+ # Theorem : Let gcd(a,b) = d, a = d*p, b = d*q. If (x0,y0) is a solution of Diophantine
34
+ # Equation a*x + b*y = c. a*x0 + b*y0 = c, then all the solutions have the form
35
+ # a(x0 + t*q) + b(y0 - t*p) = c, where t is an arbitrary integer.
34
36
35
37
# n is the number of solution you want, n = 2 by default
36
38
@@ -75,8 +77,9 @@ def greatest_common_divisor(a, b):
75
77
>>> greatest_common_divisor(7,5)
76
78
1
77
79
78
- Note : In number theory, two integers a and b are said to be relatively prime, mutually prime, or co-prime
79
- if the only positive integer (factor) that divides both of them is 1 i.e., gcd(a,b) = 1.
80
+ Note : In number theory, two integers a and b are said to be relatively prime,
81
+ mutually prime, or co-prime if the only positive integer (factor) that
82
+ divides both of them is 1 i.e., gcd(a,b) = 1.
80
83
81
84
>>> greatest_common_divisor(121, 11)
82
85
11
@@ -91,7 +94,8 @@ def greatest_common_divisor(a, b):
91
94
return b
92
95
93
96
94
- # Extended Euclid's Algorithm : If d divides a and b and d = a*x + b*y for integers x and y, then d = gcd(a,b)
97
+ # Extended Euclid's Algorithm : If d divides a and b and d = a*x + b*y for integers
98
+ # x and y, then d = gcd(a,b)
95
99
96
100
97
101
def extended_gcd (a , b ):
0 commit comments