"0811 coprime test"의 두 판 사이의 차이
ph
잔글 |
잔글 |
||
| (같은 사용자의 중간 판 7개는 보이지 않습니다) | |||
| 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> | ||
| − | + | ||
| + | precisely, | ||
<pre> | <pre> | ||
| − | def | + | def iscoprime(m,n): # m>n test is not required. |
| − | |||
while m%n != 0: | while m%n != 0: | ||
| − | m, n = n, m | + | m, n = n, m%n |
| − | return n | + | return n==1 |
</pre> | </pre> | ||
| + | is가 아니고 are인가... | ||
| + | |||
| + | <disqus/> | ||
2017년 9월 3일 (일) 17:17 기준 최신판
#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
precisely,
def iscoprime(m,n): # m>n test is not required.
while m%n != 0:
m, n = n, m%n
return n==1
is가 아니고 are인가...