Coin de Gamma
10 months ago
2 changed files with 44 additions and 0 deletions
@ -0,0 +1,10 @@
|
||||
[package] |
||||
name = "hello_053" |
||||
version = "0.1.0" |
||||
edition = "2021" |
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
||||
|
||||
[dependencies] |
||||
num-bigint = "0.4.4" |
||||
num-traits = "0.2.17" |
@ -0,0 +1,34 @@
|
||||
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); |
||||
} |
Loading…
Reference in new issue