You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
643 B
35 lines
643 B
10 months ago
|
use num_bigint::BigUint;
|
||
|
use num_traits::{Zero, One};
|
||
|
|
||
|
// Calculate large fibonacci numbers.
|
||
|
fn fc(n: usize) -> BigUint {
|
||
|
let mut nn = n;
|
||
|
let mut res: BigUint = One::one();
|
||
|
|
||
|
while nn > 1 {
|
||
|
res *= nn;
|
||
|
nn-=1;
|
||
|
}
|
||
|
|
||
|
return res;
|
||
|
}
|
||
|
|
||
|
fn bn(n: usize, r: usize) -> BigUint {
|
||
|
return fc(n) / (fc(r) * fc(n-r));
|
||
|
}
|
||
|
|
||
|
|
||
|
fn main() {
|
||
|
//println!("Hello, world!");
|
||
|
//println!("fib(1000) = {}", fib(1000));
|
||
|
let mut count = 0;
|
||
|
for n in 1..=100 {
|
||
|
for r in 1..=n {
|
||
|
if bn(n, r) > BigUint::from(1000000u32) {
|
||
|
count +=1;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
println!("{}", count);
|
||
|
}
|