peuler 0.1.0

A Rust crate with solutions to the Project Euler problems
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use crate::Solution;
use pmath::phi_0_to_n;

problem!(Problem0072, 72, "Counting Fractions");

impl Solution for Problem0072 {
    fn solve(&self) -> String {
        // this is Farey sequence
        // the number of elements in the Farey sequence F(n) is given as:
        // F(n) = 1 + Σ(φ(i)) for i = 1 to n
        let farey_elements = 1 + phi_0_to_n(1_000_000).into_iter().sum::<u64>();

        // the problem excludes 0 and 1, so subtract 2 and return a result
        (farey_elements - 2).to_string()
    }
}