Three logicians walk into a bar. The bartender greets them with "Do you all want a beer?". The first logician says "I don't know.". The second also says "I don't know.". The third says "Yes.".
His wife said: "Go get a jug of milk. If they have eggs, buy a dozen". Later, his wife said: "Why did you come back with a dozen jugs of milk?" The logician said: "They had eggs."
So I am making a very simple ticket system. Enter the amount of adult tickets and kids tickets you want. Should I make the PayPal button type a buy now with the total amount or should I use their shopping cart API?
@IvanMilisavljevic Varies by the size of the number - but for a 100% accurate result you would usually need to test divisibility by the 2, 3, and all numbers k = (6x +/- 1) such that k is less than the square root of the number you are testing
There are faster options, but they tend to be probabilistic (although for any common range of numbers you'd find, the false positives are known and can be stored in a lookup table)
If you really, really want fast performance, you can hard code a lookup table of all 32 bit prime numbers in about 200 MB of memory, so....
That breaksdown for crypto level prime operations tho, since they tend to be considerably larger than 32 bits and it is generally faster to check if a given number is prime than to read a precomputed list for 4k bit numbers into memory to begin with