[蓝桥杯] 既约分数 (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
标签:既约,gcd,Python,res,蓝桥,range,2021,ans,zi 来源: https://blog.csdn.net/d_l_w_d_l_w/article/details/122217452