Skip to content

Commit 3b90c33

Browse files
authored
Add 0 check for primality test (TheAlgorithms#334)
1 parent c44be1d commit 3b90c33

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/math/miller_rabin.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ pub fn miller_rabin(number: u64, bases: &[u64]) -> u64 {
4040
// note that all bases should be prime
4141
if number <= 4 {
4242
match number {
43+
0 => {
44+
panic!("0 is invalid input for Miller-Rabin. 0 is not prime by definition, but has no witness");
45+
}
4346
2 => return 0,
4447
3 => return 0,
4548
_ => return number,

0 commit comments

Comments
 (0)