Competitive Programming: Totient Möbius
Competitive Programming: Totient Möbius
Competitive Programming
From Problem 2 Solution in O(1)
Number Theory
Totient and Möbius Functions
◼ Online Sequence
◼ φ(n) = 1, 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
◼ φ(1) = φ(2) = 1. φ(5) = 4
◼ φ(n) is even for n > 2
◼ sqrt(n) <= φ(n) <= n - sqrt(n): Except 2, 6
◼ φ(nk) = nk-1 * φ(n)
◼ n = ∑iφ(di) where d are the divisors of n
Menon's identity
d(n): # of n divisors
◼ μ(1) = 1
◼ μ(n) = 1 if n is a square-free positive integer
with an even number of prime factors.
◼ E.g. μ(2*3*5*7) = 1
◼ μ(n) = −1 if n is a square-free positive integer
with an odd number of prime factors.
◼ E.g. μ(2*3*5) = -1
◼ μ(n) = 0 if n has a squared prime factor.
◼ E.g. μ(2*3*3*7) = 0
Möbius sequence
ﻋﻠﻤﻜﻢ ﷲ ﻣﺎ ﯾﻨﻔﻌﻜﻢ
وزادﻛﻢ ﻋﻠﻤﺎ ً
Problems