"0811 coprime test"의 두 판 사이의 차이

ph
이동: 둘러보기, 검색
잔글
잔글
8번째 줄: 8번째 줄:
 
def iscoprime(a,b):
 
def iscoprime(a,b):
 
     return gcd(a,b) == 1
 
     return gcd(a,b) == 1
 +
</pre>
 +
 +
precisely,
 +
<pre>
 +
def iscoprime(m,n):
 +
    while m%n != 0:
 +
        m, n = n, m%n
 +
    return n==1
 
</pre>
 
</pre>

2017년 8월 11일 (금) 16: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):
    while m%n != 0:
        m, n = n, m%n
    return n==1