Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Revisions

5 of 7
deleted 135 characters in body
Dennis
  • 211.7k
  • 41
  • 380
  • 830

Jelly, (削除) 12 (削除ここまで) 8 bytes

RÆṪSḤ’÷2

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....

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

AltStyle によって変換されたページ (->オリジナル) /