I hope i have this pasted right

http://www.math.com/...rime-number.htm

I have access to a couple of c++ compilers I am learning on.

<!-- Begin function calculate(form) { var num=parseInt(form.number.value); if (isNaN(num) || num < 0) { form.result.value=(form.number.value + " is not a valid number! Try again!"); } if (num == 1) { form.result.value=("1 is not prime by definition!"); } if (num == 0) { form.result.value=("0 is not a valid number."); } if (num == 2) { form.result.value=("2 is a prime number!"); } for (var i=2;i<num;i++) { if (num % i == 0) { var prime="yes"; form.result.value=(num + " is not prime. It is divisible by " + i + "."); break; } if (num % i != 0) var prime="no"; } if (prime == "no") form.result.value=(num + " is prime!"); } // End --> </SCRIPT> <P align="left"> <div align="left"> <table width="100%" border="0" cellspacing="2" cellpadding="2"> <tr> <td> <div align="left"><font size=6><font size="+2" align=RIGHT color="#0000FF"><font color="#CC6600" size="+1">Prime Number</font></font><br> </font> <table border=0 width=486 cellpadding=3 cellspacing=0> <tr> <td>Enter a number and the Prime Number Calculator will instantly tell you if it is a prime number or not.</td> </tr> </table> </div> <form name=form> <div align="left"> <p>Please enter a number: <input type=text name=number size=10> <br> <input type=button value="Is it prime?" onclick="calculate(this.form)" name="button"> <input type=text name=result size=45 value=""> <br> </p> </div> </form> </td> </tr> <tr> <td>Prime numbers are positive, non-zero numbers that have exactly two factors -- no more, no less.</td> </tr> </table> </div> <hr> <div align="right"><br> </div> <P align="left"> <!-- #EndEditable --></td> <td> </td> <td valign="top"> <table width="0" border="0" cellspacing="0" cellpadding="0">

any help much appreciated. If your writing a sieve program for programmers it will be of value for you to do 2 things

#1. Look at a list of primes such as found at the first 1,000 primes at

http://primes.utm.ed.../small/1000.txt

and please note that each prime ends in 1,3,7 or 9 only. This means you can greatly increase your odds of finding primes by chosing numbers that end in 1,3,7 or 9 and you may look at even larger primes and you will see that all end in either 1,3,7 or 9.

#2 that no composite you find will have a whole number divisor more

than 50% its value (other than the number itself), for example the highest whole number divisor of 16 is 8, 8 is 50% of 16. You can enter each composite you find and it will say its highest whole number divisor is not more than 50% of the value of the number entered.

This means you only have to use 1/2 the numbers of the number being tested for primality instead of diving the number of times of the number tested using a sieve program. I invite you to use a percent calculator or do the math yourself calculate what percent of the highest whole number divisor of any composite is you find, no composites highest whole number divisor will be more than 50% of its value (other than the composite itself).

For example to find out if 16 has two divisors of one and

itself you normally would divide 16 by numbers 1-16. Instead all

you will have to do is find 50% of the number you wish and do numbers

1-50% of the number entered in this case divide 16 by numbers 1-8 to find if 16 has a whole number divisor. That should save you half the time.

thought that might help prime finders save some time .

By the way an easy way of finding out 50% of a number or amount, divide the number by 2. you can round down to the nearest whole number if it ends in a decimal (.50).

This post has been edited by **jayman9**: 10 June 2007 - 10:45 AM