Rust Implementation of Problem 53
View source code here on GitHub!
Includes
Problem Solution
- pub fn problems::p0053::p0053() -> utils::Answer
1/*
2Project Euler Problem 53
3
4Problem:
5
6There are exactly ten ways of selecting three from five, 12345:
7
8123, 124, 125, 134, 135, 145, 234, 235, 245, and 345
9
10In combinatorics, we use the notation, 5C3=10
11
12.
13
14In general, nCr=n!r!(n−r)!
15, where r≤n, n!=n×(n−1)×...×3×2×1, and 0!=1
16
17.
18
19It is not until n=23
20, that a value exceeds one-million: 23C10=1144066
21
22.
23
24How many, not necessarily distinct, values of nCr
25for 1≤n≤100, are greater than one-million?
26*/
27use crate::include::math::n_choose_r;
28use crate::include::utils::Answer;
29
30pub fn p0053() -> Answer {
31 let mut answer: u64 = 0;
32 for n in 1..101 {
33 for r in 2..(n-1) {
34 if n_choose_r::<u128>(n, r) > 1_000_000 {
35 answer += 1;
36 }
37 }
38 }
39 return Answer::Int(answer.into());
40}