ok I need help coding this up in Java. I really dont understand any explanation of how exaclty a prime number decomposition algorithm works (in math terms). Does anyone know anything about this? Can you help me figure out a Java algo for it?
To find out if a number is a prime number you devide it by every integer starting from 2 up to the square root of the nuber you’re analyzing. Of course, the program will run a little faster is you skip as many integers as possible (like storing previously found primes in an arraylist and only deviding by those instead of every integer).
in it’s simplest form:
if (number % dividebythisnumber == 0)
{
// number is a prime.
}
The method will work. It sounds very tedious and will take awhile if you use very large number, but unless you are checking to see if special types of numbers (i.e. (2^n)-1 ) are prime there isn’t much else you could do.
couple of things you should know…
- all primes end with either 1,3,7 or 9
- the last digit is evenly distibuted. I tried it with 100000 primes, and all last digits occured 25000 ± 5 times.
[quote] - all primes end with either 1,3,7 or 9
[/quote]
5

store them in an array as you create them. Store 1, 3, 5, 7, 11 in the first indexes and then those rules will suit you fine 
That’s the one exception T_T
2 