pgcd.py

Created by polettielio

Created on April 13, 2023

300 Bytes

Computes and prints each step of the Euclidea Algorithm.


from math import floor

def fmt(s, *a):
  return s.format(*a)

def pgcd(a, b):
  if a<b:
    r=a
    a=b
    b=r
  r=a%b
  q=floor(a/b)
  print(fmt("{} = {} ({}) + {}",a,q,b,r))
  while r>0:
    a=b
    b=r
    r=a%b
    q=floor(a/b)
    print(fmt("{} = {} ({}) + {}",a,q,b,r))
  return b