That's the name of the lesson I just completed on LEARN.
Ummm... It was tricky! Basically I had to write a code that determined whether or not a number was a prime number - returning true if it was and false if it wasn't. At first I tried to use the pseudocode on the Wikipedia Primality Test page, but that didn't work. So I did some more research on primes and came across the form 6k + 1:
If a number leaves a remainder of 0, 2 or 4 when divided by 6, then it is even and therefore non-prime (unless it is 2). If it leaves a remainder of 3 when divided by 6 then it is divisible by 3 and therefore non-prime (unless it is 3). That leaves just the remainders 1 and 5, or in other words, numbers of the form 6k±1.
So I tried to rework this logic and use it as my code, but despite trying a bunch of different if and elsif statements I could only get 1 of the 2 tests to pass. It was always one or the other, not both. (I should have figured, when I tested the math out on paper it didn't work for numbers like 35 or 121.)
Then I came across this on Wiki:
Let's look at another example, and use trial division to test the primality of 17. Since we now know we do not need to test using divisors greater than √n, we only need to use integer divisors less than or equal to . Those would be 2, 3, and 4. As stated above, we can skip 4 because if 4 evenly divides 17, 2 must also evenly divide 17, which we already would have checked before that. That leaves us with just 2 and 3. After dividing, we find that 17 is not divisible by 2 or 3, and we can confirm that 17 must be prime.
This, with the combination of a contribution from a fellow student on LEARN and some Googles set the light bulb off - and the tests passed (literally the best feeling ever)! Hip Hip Hooray!
Or Hip Hop Hooray!