파이썬 math.gcd() 메서드
예시
두 정수의 최대 공약수를 구합니다.
#Import math Library
import math
#find the the greatest
common divisor of the two integers
print (math.gcd(3, 6))
print (math.gcd(6,
12))
print (math.gcd(12, 36))
print (math.gcd(-12, -36))
print (math.gcd(5,
12))
print (math.gcd(10, 0))
print (math.gcd(0, 34))
print (math.gcd(0,
0))
정의 및 사용
이 메서드는 두 정수 int1 및 int2math.gcd()
의 최대 공약수를 반환합니다 .
GCD는 나머지 없이 숫자를 나누는 가장 큰 공약수입니다.
GCD는 최고공약수(HCF)라고도 합니다.
팁: gcd(0,0)은 0을 반환합니다.
통사론
math.gcd(int1, int2)
매개변수 값
Parameter | Description |
---|---|
int1 | Required. The first integer to find the GCD for |
int2 | Required. The second integer to find the GCD for |
기술적 세부 사항
반환 값: | int 두 정수에 대한 최대공약수(GCD)를 나타내는 값 |
---|---|
파이썬 버전: | 3.5 |