Problem 72: Counting fractions

Consider the fraction, $\frac{n}{d}$, where n and d are positive integers. If n < d and highest common factor, ${HCF}(n, d) = 1$, it is called a reduced proper fraction.

If we list the set of reduced proper fractions for d ≤ 8 in ascending order of size, we get:

$$\frac{1}{8}, \frac{1}{7}, \frac{1}{6}, \frac{1}{5}, \frac{1}{4}, \frac{2}{7}, \frac{1}{3}, \frac{3}{8}, \frac{2}{5}, \frac{3}{7}, \frac{1}{2}, \frac{4}{7}, \frac{3}{5}, \frac{5}{8}, \frac{2}{3}, \frac{5}{7}, \frac{3}{4}, \frac{4}{5}, \frac{5}{6}, \frac{6}{7}, \frac{7}{8}$$

It can be seen that there are 21 elements in this set.

How many elements would be contained in the set of reduced proper fractions for dlimit?

Tests

  • Waiting: 1. countingFractions(8) should return a number.
  • Waiting: 2. countingFractions(8) should return 21.
  • Waiting: 3. countingFractions(20000) should return 121590395.
  • Waiting: 4. countingFractions(500000) should return 75991039675.
  • Waiting: 5. countingFractions(1000000) should return 303963552391.
/**
* Your test output will go here
*/