Fixed is_prime
Signed-off-by: Michael Lodder <redmike7@gmail.com>
This commit is contained in:
parent
9bec3d8036
commit
0119c6c77b
1 changed files with 5 additions and 1 deletions
|
@ -312,6 +312,10 @@ pub fn is_prime(candidate: &Int) -> bool {
|
||||||
// candidate. If the candidate divides any of them, then we know the number
|
// 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.
|
// is a multiple of that prime; that is, the candidate is composite.
|
||||||
|
|
||||||
|
if *candidate == Int::from(2) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
if !candidate.is_odd() {
|
if !candidate.is_odd() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -321,7 +325,7 @@ pub fn is_prime(candidate: &Int) -> bool {
|
||||||
let (_, r) = candidate.divmod(&prime);
|
let (_, r) = candidate.divmod(&prime);
|
||||||
|
|
||||||
if r == Int::zero() {
|
if r == Int::zero() {
|
||||||
return false;
|
return *candidate == prime;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue