document.write( "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)
\n" );
document.write( "for 10,000 it took 0.494s
\n" );
document.write( "for 20,000 it took 1.100s
\n" );
document.write( "for 30,000 it took 1.965s
\n" );
document.write( "for 40,000 it took 3.149s
\n" );
document.write( "for 50,000 it took 4.579s
\n" );
document.write( "for 60,000 it took 6.305s
\n" );
document.write( "for 70,000 it took 8.108s
\n" );
document.write( "for 80,000 it took 10.343s
\n" );
document.write( "for 90,000 it took 12.560s
\n" );
document.write( "for 100,000 it took 15.091s\r
\n" );
document.write( "\n" );
document.write( "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 \n" );
document.write( "
Algebra.Com's Answer #547447 by richard1234(7193)![]() ![]() 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.\r \n" ); document.write( " \n" ); document.write( "\n" ); document.write( "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:\r \n" ); document.write( "\n" ); document.write( "def prime(n): #this one is on Wikipedia \n" ); document.write( "___if n < 1: return False \n" ); document.write( "___if not n%2 or not n%3: return False\r \n" ); document.write( "\n" ); document.write( "___for i in xrange(5, int(n**0.5 + 1), 6): \n" ); document.write( "______if not n%i or not n%(i+2): return False \n" ); document.write( "___return True\r \n" ); document.write( " \n" ); document.write( "\n" ); document.write( "Then to generate a list of primes: \n" ); document.write( "def primeslist(n): #creates a list of primes <= n: \n" ); document.write( "___l = [] \n" ); document.write( "___for i in range(1, n+1): \n" ); document.write( "______if prime(i): l.append(i) \n" ); document.write( "___return l\r \n" ); document.write( "\n" ); document.write( "Of course there are faster methods but it only took 0.5 seconds to create the list.\r \n" ); document.write( " \n" ); document.write( "\n" ); document.write( " \n" ); document.write( " |