import math
import pickle
def prime_list(n):
sieve = [True] * (n+1) # true: prime, false: not prime. default: true
for i in range(2, int(math.sqrt(n))+1):
if sieve[i] == True:
for j in range(i+i, n+1, i):
sieve[j] = False
return [i for i in range(2,n+1) if sieve[i] == True]
list1 = prime_list(1000000000)
with open("prime_10^9.pickle","wb") as fw:
pickle.dump(list1, fw)
When I make a decimal list with Eratosthenes, I make a decimal list with less than 108 but I get a memory error from 109. What should I do? Should I use a different data type instead of a list? For your information, modules such as numpy cannot be used.
89 python primes
I'm not sure what type Python bullion is made of, but if it's int type, not real 1 bit, then True N will have the same memory capacity as 32-bit int N. So, we initialize each array of elements to 0xFFFFFF, and we set 32 true bits per element, so we can save 32 times the memory through bit operations. If you want to do this, you have to calculate the beat well.
If you want to try Erastothenes' methods and get more than a few...
primes = get_primes_erasto(N)
candidate = smallest_odd_number_greater_than(N)
while candidate < VERYVERYBIGN:
for prime in primes:
if candidate % prime:
break
if candidate < prime*prime:
primes.append(candidate)
break
candidate += 2
There's probably a way to do it like this way. I don't know if it's efficient.
581 PHP ssh2_scp_send fails to send files as intended
573 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
613 GDB gets version error when attempting to debug with the Presense SDK (IDE)
916 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
574 Who developed the "avformat-59.dll" that comes with FFmpeg?
© 2024 OneMinuteCode. All rights reserved.