0811 coprime test

ph
Admin (토론 | 기여)님의 2017년 8월 11일 (금) 16:12 판
이동: 둘러보기, 검색
#coprime test
def gcd(m,n):
    q = m%n
    if q ==0:
        return n
    else:
        return gcd(n, q)

def iscoprime(a,b):
    return gcd(a,b) == 1

without recursion,

def gcd(m,n):
    while m%n != 0:
        m, n = n, m-n*(m/n)
    return n