Skip to content

Commit 737e53b

Browse files
committed
Fix case, that 1 is prime
1 parent e592ed6 commit 737e53b

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

Miller-Rabin Primality Test/MRPrimality.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@ enum MillerRabinError: Error {
2626
*/
2727
func checkWithMillerRabin(_ n: UInt, accuracy k: UInt = 1) throws -> Bool {
2828
guard k > 0 else { throw MillerRabinError.primeLowAccuracy }
29-
guard n > 0 else { throw MillerRabinError.primeLowerBorder }
30-
guard n > 3 else { return true }
31-
29+
if n <= 3 return n >= 2
30+
3231
// return false for all even numbers bigger than 2
3332
if n % 2 == 0 {
3433
return false

0 commit comments

Comments
 (0)