SOLUTION: I am trying to run a program that tells me how many prime numbers there are in a range of numbers. I run it in intervals of 10,000 to 100,000. How long would the program take to de
Algebra.Com
Question 902616: I am trying to run a program that tells me how many prime numbers there are in a range of numbers. I run it in intervals of 10,000 to 100,000. How long would the program take to determine all the prime numbers between 2 and the largest known primes (with about 13 million digits)
for 10,000 it took 0.494s
for 20,000 it took 1.100s
for 30,000 it took 1.965s
for 40,000 it took 3.149s
for 50,000 it took 4.579s
for 60,000 it took 6.305s
for 70,000 it took 8.108s
for 80,000 it took 10.343s
for 90,000 it took 12.560s
for 100,000 it took 15.091s
According to what I have now, How would I find the solution? I do understand that this will take a very long time, but how long exaclty
Found 2 solutions by richwmiller, richard1234:
Answer by richwmiller(17219) (Show Source): You can put this solution on YOUR website!
plot the points
use 10 for 10,000
Answer by richard1234(7193) (Show Source): You can put this solution on YOUR website!
That depends on the asymptotic runtime of your prime-checking algorithm, and you would also need a ton of space.
By the way, 15 seconds to check all primes up to 100000 seems pretty slow. I was able to create a list of primes up to 100000 in about 0.5 sec. Here is some example Python code:
def prime(n): #this one is on Wikipedia
___if n < 1: return False
___if not n%2 or not n%3: return False
___for i in xrange(5, int(n**0.5 + 1), 6):
______if not n%i or not n%(i+2): return False
___return True
Then to generate a list of primes:
def primeslist(n): #creates a list of primes <= n:
___l = []
___for i in range(1, n+1):
______if prime(i): l.append(i)
___return l
Of course there are faster methods but it only took 0.5 seconds to create the list.
RELATED QUESTIONS
If I can run 1000 yards in 6 minutes and there are 1760 yards in a mile. How long would... (answered by macston)
How can you know how many number there are in a given sequence?
For example from 1 to... (answered by jsmallt9)
I run a mile in 8 minutes. How long will it take me to run 1,300 miles?
(answered by Alan3354)
This question is pretty simple but i honestly don't understand it.
A runner leaves... (answered by ikleyn)
"Untitled," by Stephen Chen
"I've often wondered how software is released and sold to... (answered by CPhill)
Please help me solve this question. You can program some CD players to choose randomly in (answered by DrBeeee)
How many prime numbers are there whose squares are less than 250? And please could you... (answered by ewatrrr)
Find the probability of getting a prime number in the case that a number is chosen... (answered by richard1234)
Hi, I am more of an older folk here so its not for homework. Actually it was a question (answered by jim_thompson5910)