MCPcopy Create free account
hub / github.com/E869120/math-algorithm-book / GCD

Function GCD

codes/python/Code_3_02_2.py:3–11  ·  view source on GitHub ↗
(A, B)

Source from the content-addressed store, hash-verified

1# 正の整数 A と B の最大公約数を返す関数
2# GCD は Greatest Common Divisor(最大公約数)の略
3def GCD(A, B):
4 while A >= 1 and B >= 1:
5 if A < B:
6 B = B % A # A < B の場合、大きい方 B を書き換える
7 else:
8 A = A % B # A >= B の場合、大きい方 A を書き換える
9 if A >= 1:
10 return A
11 return B
12
13A, B = map(int, input().split())
14print(GCD(A, B))

Callers 1

Code_3_02_2.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected