# [Fundamental Information Technology Engineer Examination] I wrote the algorithm of Euclidean algorithm in Python.

# Overview

--There is an algorithm in the afternoon exam of the Fundamental Information Technology Engineer Examination. I can't understand even if I solve the past questions ... I would like to actually write the algorithm in Python to deepen my understanding.

――First of all, let's write from the algorithm of ** Euclidean algorithm **.

## Euclidean algorithm

#### algorithm

--Repeat subtracting the smaller of the two integers from the larger one until they are equal. The equalized value is the greatest common divisor.
--GCM is the Greatest Common Measure (greatest common divisor)

#### code

```
#GCM function to find the greatest common divisor by Euclidean algorithm
def GCM(A,B):
#Iterative processing
while A != B: #Repeat until A and B are equal
print("A=",A,"B=",B) #Results on the way
#Branch processing
if A > B: #If A is greater than B
A = A - B #A to A-Store B
else:
B = B - A #B to B-Store A
return A
print("Execution result:",GCM(84,60))
```

#### Execution result

```
A= 84 B= 60
A= 24 B= 60
A= 24 B= 36
A= 24 B= 12
Execution result: 12
```

# Summary

――It was better to actually write the program than to just think about it.
――Next time, let's write a leap year algorithm

# reference

--I quoted or referred to Chapter 3 01 Euclidean algorithm in this book.
Information processing textbook, book that can solve algorithm problems of the Fundamental Information Technology Engineer Examination, 2nd edition