题目:
代码:
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