Euclidean Algorithm

First of all, What is a Euclidean Algorithm?

Euclidean Algorithm is a algorithm that gets the greatest common divisor

This algorithm usually made with a simple praise x % y=r and y % r 's greatest common divisor is same with x % y

This is the core mechanism of the Euclidean Algorithm

I'll show you guys the simplest way of coding the Euclidean Algorithm

C/C++

#include<stdio.h>
int main()
{
    int i,x,y,r,temp;
    scanf("%d %d",&x,&y);
    while(1)
    {
        r=x%y;
        if(!r)break;
        else x=y,y=r;
    }
    printf("%d",y);
    return 0;
}

Python

x=int(input())
y=int(input())
while 1:
    r=x%y
    if r==0:break
    else :
        x=y
        y=r
print(y)