Browse Source

053 ok

master
Coin de Gamma 12 months ago
parent
commit
e64abdbeef
  1. 10
      053/Cargo.toml
  2. 34
      053/src/main.rs

10
053/Cargo.toml

@ -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"

34
053/src/main.rs

@ -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…
Cancel
Save