=GvwW%GQAGQ=GvwWQAGQ,Q%GQ)QG
This program uses the Euclidean algorithm, and takes two numbers separated by a newline. Try it onlineTry it online.
Q = eval(input()) #
G = eval(input()) # =Gvw
while G % Q != 0: # W%GQWQ
G, Q = Q, G % Q # AGQ,Q%GQ)
print(QG) # QG