add 素数筛.

This commit is contained in:
Licsber 2022-04-10 05:50:28 +08:00
parent 4a67c4295a
commit be353533a7
3 changed files with 15 additions and 18 deletions

View File

@ -67,27 +67,9 @@ def lcm(a, b):
return a * b // math.gcd(a, b)
def cal_prime_nums(n):
prime = [1] * (n + 1)
prime[0] = prime[1] = 0
for i in range(2, n + 1):
j = i * i
while j <= n:
prime[j] = 0
j += i
res = []
for idx, num in enumerate(prime):
if num:
res.append(idx)
return res
ans = 2022040920220409
check(ans)
prime = cal_prime_nums(99)
ans = 1
product = 1
for num, mod in nums:

0
utils/__init__.py Normal file
View File

15
utils/cal_prime.py Normal file
View File

@ -0,0 +1,15 @@
def cal_prime(n):
prime = [1] * (n + 1)
prime[0] = prime[1] = 0
for i in range(2, n + 1):
j = i * i
while j <= n:
prime[j] = 0
j += i
res = []
for idx, num in enumerate(prime):
if num:
res.append(idx)
return res