Rust:
use num::Integer; fn proper_fractions(d: usize) -> usize { (1..d).filter(|n| d.gcd(n) == 1).count() } #[cfg(test)] mod tests { use super::*; #[test] fn test_examples() { assert_eq!(proper_fractions(0), 0); assert_eq!(proper_fractions(1), 0); assert_eq!(proper_fractions(2), 1); assert_eq!(proper_fractions(5), 4); assert_eq!(proper_fractions(15), 8); assert_eq!(proper_fractions(25), 20); } }
Two beers for the num crate (for gcd) :)
num
gcd
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Rust:
Two beers for the
num
crate (forgcd
) :)