- 判断一个数是不是素数
def isPrime(n):
if n <= 1:
return Flase
i = 2
while i*i <= n:
if n%i == 0:
return Flase
i += 1
return True
- 求取两个数的最大公约数
def gcd(a, b):
# return the GCD of a and b using Euclid's Algorithm
while a != 0:
a, b = b % a, a
return b
网友评论