Simplified Proper Fractions

Published by Deep Xavier in

Create a function that takes a number maxDen and returns the total number of fully simplified proper fractions that exist with denominator less than or equal to maxDen.

You only need to return the number of fractions; NOT the fractions themselves. In the examples below, the fractions are enumerated for your reference.

Examples

simPropFrac(10) ➞ 31
// 1/2, 1/3, 2/3, 1/4, 3/4, 1/5, 2/5, 3/5, 4/5, 1/6, 5/6, 1/7, 2/7, 3/7, 4/7, 5/7, 6/7, 1/8, 3/8, 5/8, 7/8, 1/9, 2/9, 4/9, 5/9, 7/9, 8/9, 1/10, 3/10, 7/10, 9/10

simPropFrac(7) ➞ 17
// 1/2, 1/3, 2/3, 1/4, 3/4, 1/5, 2/5, 3/5, 4/5, 1/6, 5/6, 1/7, 2/7, 3/7, 4/7, 5/7, 6/7

Notes

  • A fully simplified proper fraction is a fraction where both the numerator and the denominator share no common factor but 1 and that the fraction is less than 1.
Watch a quick demo on how Edabit works.