def gcd_steps(a, b):
steps = []
# this is the standard GCD finding algorithm;
# we simply amend it with "step tracking"
while b:
# a, b = b, a % b
tmp = a
a = b
b = tmp % b
steps.append(a)
return steps # normally we'd want to return `a`
# but you want the steps not just the result
steps = gcd_steps(125 * 123 * 12314, 25 * 149)
# print the list with `->` between the steps
print(" -> ".join(str(x) for x in steps))
(the result would be the last step, which you can access by taking the last element of the list: steps[-1]
)
Output:
3725 -> 900 -> 125 -> 25