Jelly, (削除) 12 (削除ここまで) 8 bytes
RÆṪSḤ’÷2
The following binary code works with this version of the Jelly interpreter.
0000000: 52 91 b0 53 aa b7 9a 8a R..S....
How it works
RÆṪSḤ’÷2 Input: n
R Yield [1, ..., n].
ÆṪ Apply Euler's totient function to each k in [1, ..., n].
This yields the number of coprimes to k, less than or equal to k.
S Compute the sum of all results.
This yields the number of coprime pairs (j, k) such that j ≤ k.
Ḥ Multiply the result by 2.
This accounts for all (k, j) pairs, too.
’ Subtract 1 to account for counting (1, 1) twice.
÷2 Divide the result by n2.
Dennis
- 211.7k
- 41
- 380
- 830