A384710 a(n) = Sum_{k=0..n} [gcd(k, n) = 1], where [.] are the Iverson brackets.
0, 2, 1, 2, 2, 4, 2, 6, 4, 6, 4, 10, 4, 12, 6, 8, 8, 16, 6, 18, 8, 12, 10, 22, 8, 20, 12, 18, 12, 28, 8, 30, 16, 20, 16, 24, 12, 36, 18, 24, 16, 40, 12, 42, 20, 24, 22, 46, 16, 42, 20, 32, 24, 52, 18, 40, 24, 36, 28, 58, 16, 60, 30, 36, 32, 48, 20, 66, 32, 44, 24
Offset: 0
Keywords
Examples
[gcd(0,0)] = [0] => a(0) = 0. [gcd(0,1), gcd(1,1)] = [1, 1] => a(1) = 2. [gcd(0,2), gcd(1,2), gcd(2,2)] = [2, 1, 2] => a(2) = 1.
References
- R. L. Graham, D. E. Knuth and O. Patashnik, Concrete Mathematics, Addison-Wesley, 2nd ed., 1994, ch. 4.5.
Programs
-
Maple
isPrimeTo := (k, n) -> ifelse(igcd(k, n) = 1, 1, 0): a := n -> add(isPrimeTo(k, n), k = 0..n): seq(a(n), n = 0..70);
-
Mathematica
Table[Sum[Boole[CoprimeQ[k, n]], {k, 0, n}], {n, 0, 70}] (* Michael De Vlieger, Jun 07 2025 *)
-
PARI
a(n) = sum(k = 0, n, gcd(k, n) == 1); \\ Amiram Eldar, Jun 08 2025
-
Python
from math import gcd def a(n: int) -> int: return sum(int(1 == gcd(n, k)) for k in range(n + 1)) print([a(n) for n in range(71)])
Comments