[蓝桥杯] 既约分数 (Python 实现)

题目:
[蓝桥杯] 既约分数 (Python 实现)
代码:

def check (a,b):
    res = 0
    for x in range(1,min(a,b)+1):
        if (a % x == 0) and (b % x == 0):
            res = x
    return res
ans = 0
for a in range(1,2021):
    for b in range(1,2021):
        if check(a,b) == 1:
            ans +=1
print(ans)
def gcd(a, b):
    return a if b == 0 else gcd(b, a % b)
ans = 0
for zi in range(1, 2021):
    for mu in range(1, 2021):
        if gcd(zi, mu) == 1:
            ans += 1
print(ans)

结果:2481215

上一篇:shell基本语法-变量


下一篇:Algorithm Of Swift -- 4.合并两个有序数组