Exercise 514
Write an algorithm in Python which determines the list of pairs of integers (m, n) satisfying:
- GCD (2m - 1, 2n + 1) = 3
- 0 < m < 100 and 0 < n < 100
Solution
def gcd (m , n):
d = m
while(m%d !=0 or n%d !=0):
d = d - 1
return d
listSolutions = []
for m in range(1 , 100):
for n in range(1, 100):
if gcd(2*m-1, 2*n+1) == 3:
listSolutions.append((m , n))
print(listSolutions)
Younes Derfoufi
my-courses.net
my-courses.net