In this case the cache is built using a python dictionary. We can check this dictionary first before computing whether a given number is prime.
for i in range(2, x):
This syntax counts from 2 to x-1 and assigns the number to i. We have to do this to test if x is ever divisible by i without a remainder. If we ever modulus x by i and get 0 (no remainder) then x is not prime.
Comments
instead of writing this line
for i in range( 2, x ):Can't we use the cache to build a prime list for our advantage?
for i in primes_list:export
In this case the
cacheis built using a python dictionary. We can check this dictionary first before computing whether a given number is prime.for i in range(2, x):This syntax counts from
2tox-1and assigns the number toi. We have to do this to test ifxis ever divisible byiwithout a remainder. If we ever modulusxbyiand get0(no remainder) thenxis not prime.export
Update - My new laptop is significantly faster at computing primes:
export
thanks
export