Use correct formula

This commit is contained in:
Vinzent Steinberg 2017-03-12 10:23:27 +01:00
parent 07df43b034
commit 40cbe1ff20
1 changed files with 1 additions and 4 deletions

View File

@ -668,11 +668,8 @@ impl_integer_for_usize!(usize, test_integer_usize);
/// Calculate r * a / b, avoiding overflows and fractions.
fn multiply_and_divide<T: Integer + Clone>(r: T, a: T, b: T) -> T {
// See http://blog.plover.com/math/choose-2.html for the idea.
//
// This depends on the fact that `b` must evenly divide `r*a`, as that's
// what lets you know that `b/gcd(r, b)` divides `a` evenly.
let g = gcd(r.clone(), b.clone());
(r/g.clone()) * (a / (b/g))
(r/g.clone() * a) / (b/g)
}
/// Calculate the binomial coefficient.