ares/rust/ibig/examples/factorial.rs
Edward Amsden a7005c7049 Ares -> Sword (#12)
* Update README.md

* Rename ares -> sword

* Workspace

* Cargo-only CI
2024-08-22 10:46:38 -05:00

18 lines
344 B
Rust

use ibig::UBig;
// a * (a+1) * ... * (b-1)
fn product(a: u32, b: u32) -> UBig {
if b == a + 1 {
UBig::from(a)
} else {
let mid = a + (b - a) / 2;
product(a, mid) * product(mid, b)
}
}
fn main() {
let n: u32 = 1000000;
let factorial = product(1, n + 1);
println!("{}! = {:#x}", n, factorial);
}