codility CommonPrimeDivisors

来源:互联网 发布:淘宝直播间看不到聊天 编辑:程序博客网 时间:2024/05/24 04:34

Question:codility Lesson10 MinPerimeterRectangle

My Answer:

def gcd(a,b):    if (a % b == 0):        return b    else:        return gcd(b,a%b)def solution(A,B):    cnt = 0    for i in range(len(A)):        a = A[i]        b = B[i]        gcdmax = gcd(a,b)        while True:            x = gcd(a,gcbmax)            if x == 1:                break            a /= x        while True:            y = gcd(b,gcdmax)            if y == 1:                break            b /= y        cnt += 1 if a == 1 and b == 1 else 0    return cnt
原创粉丝点击