From 737e53beede2b7250607e7a868bed3a8b192eebd Mon Sep 17 00:00:00 2001 From: Tiza59 Date: Thu, 17 Mar 2022 19:55:05 +0100 Subject: [PATCH] Fix case, that 1 is prime --- Miller-Rabin Primality Test/MRPrimality.swift | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Miller-Rabin Primality Test/MRPrimality.swift b/Miller-Rabin Primality Test/MRPrimality.swift index 24b9c674c..a82bfa366 100644 --- a/Miller-Rabin Primality Test/MRPrimality.swift +++ b/Miller-Rabin Primality Test/MRPrimality.swift @@ -26,9 +26,8 @@ enum MillerRabinError: Error { */ func checkWithMillerRabin(_ n: UInt, accuracy k: UInt = 1) throws -> Bool { guard k > 0 else { throw MillerRabinError.primeLowAccuracy } - guard n > 0 else { throw MillerRabinError.primeLowerBorder } - guard n > 3 else { return true } - + if n <= 3 return n >= 2 + // return false for all even numbers bigger than 2 if n % 2 == 0 { return false