Primality by Wilson's theorem: Difference between revisions
Content added Content deleted
No edit summary |
(Better explained there) |
||
Line 6: | Line 6: | ||
Remember that '''1''' and all non-positive numbers are not prime. |
Remember that '''1''' and all non-positive numbers are not prime. |
||
Use Wilson's theorem. |
Use [http://www.cut-the-knot.org/blue/Wilson.shtml Wilson's theorem.] |
||
(% stands for modulo, ! stands for factorial, ² stands for squaring.) |
|||
Wilson's theorem states that when the following expression [needs verification] evaluates to the n - 1: |
|||
<pre> |
|||
(n-1)!%n |
|||
</pre> |
|||
The number is a prime number. |
|||
There's also a shorthand for this expression (evaluates into 1 if the number is prime, 0 otherwise): |
|||
<pre> |
|||
(n-1)!²%n |
|||
</pre> |
Revision as of 04:39, 1 January 2020
Primality by Wilson's theorem
You are encouraged to solve this task according to the task description, using any language you may know.
You are encouraged to solve this task according to the task description, using any language you may know.
- Task
Write a boolean function that tells whether a given integer is prime.
Remember that 1 and all non-positive numbers are not prime.