From e323ba3c3bf6bb5b738856d421009cb16a39fe89 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Fri, 19 Jul 2019 09:17:16 +0300 Subject: [PATCH] Update fermat_test.md --- snippets/fermat_test.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/snippets/fermat_test.md b/snippets/fermat_test.md index 0089a3237..676cf6435 100644 --- a/snippets/fermat_test.md +++ b/snippets/fermat_test.md @@ -2,7 +2,10 @@ Checks if the number is prime or not. Returns True if passed number is prime, and False if not. -The function uses Fermat's theorem. First, it picks the number A in range 1..(n-1), then it checks if A to the power of n-1 modulo n equals 1. If not, the number is not prime, else it's pseudoprime with probability 1/2. Appling this test k times we have probability 1/(2^k). For example, if the number passes the test 10 times, we have probability 0.00098. +The function uses Fermat's theorem. +First, it picks the number `A` in range `1`..`(n-1)`, then it checks if `A` to the power of `n-1` modulo `n` equals `1`. +If not, the number is not prime, else it's pseudoprime with probability 1/2. Applying this test `k `times we have probability `1/(2^k)`. +For example, if the number passes the test `10` times, we have probability `0.00098`. ``` python from random import randint