add 素数筛.
This commit is contained in:
parent
4a67c4295a
commit
be353533a7
@ -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
0
utils/__init__.py
Normal file
15
utils/cal_prime.py
Normal file
15
utils/cal_prime.py
Normal 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
|
Loading…
Reference in New Issue
Block a user