David Harrison
05-31-2003, 02:54 PM
Just a couple of questions, first of all does it matter if I don't define how many numbers, (in my case), there are in an array. If it does then does it matter if I tell it that there are, for example 1000 numbers and the only fill it with say, 100 and leave the others blank.
Now for the next question how can I make this prime number finder faster.
<html>
<head>
<title>Primes</title>
</head>
<body>
<script language="javascript">
l=1000;n=3;p=1;
primes = new Array()
primes[0]=2;
while(n<=l){q=1;
if((n-1)/1000==Math.round((n-1)/1000)){window.status="Numbers checked so far: "+(n-1);}
while(primes[q]<=Math.floor(Math.sqrt(n)) && n/primes[q]!=Math.round(n/primes[q])){q++;}
if(n/primes[q]!=Math.round(n/primes[q])){primes[p]=n;p++;}
n+=2;}
window.status="Up to and including "+l+" there are "+p+" prime numbers.";
document.write("The following numbers are all prime numbers:<br>"+primes.join(", "));
</script>
</body>
</html>
because although it only takes a blink of an eye to run this script even with the 395MHz pentium 2 that I'm using now, I need to find much bigger (100's of millions bigger) prime numbers.
If you've any ideas, then please let me know.
Now for the next question how can I make this prime number finder faster.
<html>
<head>
<title>Primes</title>
</head>
<body>
<script language="javascript">
l=1000;n=3;p=1;
primes = new Array()
primes[0]=2;
while(n<=l){q=1;
if((n-1)/1000==Math.round((n-1)/1000)){window.status="Numbers checked so far: "+(n-1);}
while(primes[q]<=Math.floor(Math.sqrt(n)) && n/primes[q]!=Math.round(n/primes[q])){q++;}
if(n/primes[q]!=Math.round(n/primes[q])){primes[p]=n;p++;}
n+=2;}
window.status="Up to and including "+l+" there are "+p+" prime numbers.";
document.write("The following numbers are all prime numbers:<br>"+primes.join(", "));
</script>
</body>
</html>
because although it only takes a blink of an eye to run this script even with the 395MHz pentium 2 that I'm using now, I need to find much bigger (100's of millions bigger) prime numbers.
If you've any ideas, then please let me know.