Co-primality and the number pi
Jelly, 12 8 bytes

RÆṪSḤ’÷²


Try it online!

The following binary code works with this version of the Jelly interpreter.

0000000: 52 91 b0 53 aa b7 9a 8a  R..S....


Idea

Clearly, the number of pairs (j, k) such that j &leq; k and j and k are co-prime equals the number of pairs (k, j) that satisfy the same conditions. Also, if j = k, j = 1 = k.

Thus, to count the number of co-prime pairs with coordinates between 1 and n, it suffices to calculate the amount m of pairs (j, k) such that j &leq; k, then compute 2m - 1.

Finally, since Euler's totient function &phi;(k) yields the number integers between between 1 and k that are co-prime to k, we can calculate m as &phi;(1) + &hellip; + &phi;(n).

Code

RÆṪSḤ’÷²    Input: n

R           Yield [1, ..., n].
 ÆṪ         Apply Euler's totient function to each k in [1, ..., n].
   S        Compute the sum of all results.
    Ḥ       Multiply the result by 2.
     ’      Subtract 1.
      ÷²    Divide the result by n².