"0811 coprime test"의 두 판 사이의 차이
ph
잔글 |
잔글 |
||
| 2번째 줄: | 2번째 줄: | ||
#coprime test | #coprime test | ||
def gcd(m,n): | def gcd(m,n): | ||
| − | + | while m%n != 0: | |
| − | + | m, n = n, m%n | |
| − | + | return n | |
| − | |||
| − | |||
def iscoprime(a,b): | def iscoprime(a,b): | ||
return gcd(a,b) == 1 | return gcd(a,b) == 1 | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
</pre> | </pre> | ||
2017년 8월 11일 (금) 16:13 판
#coprime test
def gcd(m,n):
while m%n != 0:
m, n = n, m%n
return n
def iscoprime(a,b):
return gcd(a,b) == 1