0% found this document useful (0 votes)
18 views1 page

Py

The document contains code that performs Euclid's algorithm to find the greatest common divisor of two integers. It takes in two integers, performs the Euclidean algorithm by repeatedly dividing and taking remainders, and outputs the gcd or 'No Solution' depending on the result.

Uploaded by

Eduardo Henrique
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views1 page

Py

The document contains code that performs Euclid's algorithm to find the greatest common divisor of two integers. It takes in two integers, performs the Euclidean algorithm by repeatedly dividing and taking remainders, and outputs the gcd or 'No Solution' depending on the result.

Uploaded by

Eduardo Henrique
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

c = int(input())

for k in range (c):


a, b = map(int, input().split())
tabela = [[a, b, None, None, None, None]]

while tabela[-1][1] != 0:

q = int(tabela[-1][0]/tabela[-1][1])

if tabela[-1][0] - tabela[-1][1]*q < 0:


if q < 0:
q -= 1
else:
q += 1

r = tabela[-1][0] - tabela[-1][1]*q
tabela[-1][2] = q
tabela[-1][3] = r
tabela.append([tabela[-1][1], tabela[-1][3], None, None, None, None])

tabela[-1][-2] = (0,1)
tabela[-1][-1] = (1,0)
num_linhas = len(tabela)

for i in range(num_linhas-2, -1, -1):


xl = tabela[i+1][-2]
yl = tabela[i+1][-1]
q = tabela[i][2]

tabela[i][-2] = yl
tabela[i][-1] = (xl[0] - q*yl[0], xl[1] - q*yl[1])

if tabela[0][4][1] < 0:
print("No Solution")

elif (a*tabela[0][4][1] + b*tabela[0][5][1]) == 1:


print(tabela[0][4][1],tabela[0][5][1])

else:
print("No Solution")

You might also like