Posts Tagged ‘integer’

How to determine primality as quickly as possible?

I know the easiest way of determining if an integer X is prime is to try every integer Y up to sqrt(X), and if X modulo Y = 0, then X is composite. That’s very basic.

What I want to know is, how do I test for primality faster than this? It’s easy to generate a prime number – they’re found at N!+1 where N is a positive integer. For instance, 9996!+1 is an extremely large prime. One would think the inverse of this function would be simple, and it is… but not all primes are found this way. For instance, 5 is prime but 4 is not the result of a factorial.

So… what’s the quickest way to determine if a number is prime (especially in a computer program)?

how do you create an unsigned 8 bit integer in java?

need to create an 8 bit unsigned integer in java. Would also like some help in using bit masks and bit shifting as I’m pretty sure that would be the answer to my original question.

TigerDirect