Problem I
Euclid's GCD
One of the oldest known algorithms is a method for finding the greatest common divisor of two natural numbers. It turns out that you have already learned all you need to implement it.
Given two numbers
-
Calculate the remainder of dividing
by , -
update
to be the previous value of and to be the value of the remainder.
If at any time
Input
Input consists of two lines. The first line consists of one
integer
Output
Output the greatest common divisor of
Sample Input 1 | Sample Output 1 |
---|---|
0 3 |
3 |
Sample Input 2 | Sample Output 2 |
---|---|
12 15 |
3 |
Sample Input 3 | Sample Output 3 |
---|---|
15 28 |
1 |
Sample Input 4 | Sample Output 4 |
---|---|
204 564 |
12 |
Sample Input 5 | Sample Output 5 |
---|---|
1495 715 |
65 |