From c3629c9e302f8c2e313cda52ab1329d4c496d7a1 Mon Sep 17 00:00:00 2001 From: Michael Lodder Date: Tue, 8 Jan 2019 06:42:32 -0700 Subject: [PATCH] Fixed is_prime (#10) Signed-off-by: Michael Lodder --- src/common.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/common.rs b/src/common.rs index e34a18f..27e192e 100644 --- a/src/common.rs +++ b/src/common.rs @@ -312,6 +312,10 @@ pub fn is_prime(candidate: &Int) -> bool { // candidate. If the candidate divides any of them, then we know the number // is a multiple of that prime; that is, the candidate is composite. + if *candidate == Int::from(2) { + return true + } + if !candidate.is_odd() { return false; } @@ -321,7 +325,7 @@ pub fn is_prime(candidate: &Int) -> bool { let (_, r) = candidate.divmod(&prime); if r == Int::zero() { - return false; + return *candidate == prime; } }