File
164512235712.jpg
- (3.32KB
, 119x122
, download.jpg
)
Today one of my recurring dream characters named Jennifer Zemblini gave me a prime number test that correctly validated the first few hundred prime numbers in under 3 seconds using C# code I wrote to validate her primality test!
I wanted to share the primality test with you all now.
It uses only simple division, addition and subtraction. And three variables called n, A and B.
n is defined as the number being tested for primeness. A0 is n-2 and B0 is 2.
Then apply this procedure: Divide A by B, if it is not a clean division, meaning there is a remainder, add one to B and subtract one from A, and repeat this step until B approaches one-half of n.
If A can never divide evenly into B then n is prime.
For example with n=9, which is not prime: A = 9-2. B =2. 7/2 is not even. 6/3 does evenly divide with result 2. And 3 is a factor of 9 also.
But for a prime like 13: 11/2... 10/3... 9/4... 8/5... 7/6... None of these divide cleanly with no remainder, therefore 13 is prime.
Message too long. Click here to view the full text.
4
posts
and 1
image
omitted. Click Reply to view.