Data Structures & AlgorithmsModerateICPC regional · algorithm theory
Problem: For coprime m and n, which identity for Euler's totient function is correct?
- A. phi(mn) = phi(m) * phi(n)
- B. phi(m + n) = phi(m) + phi(n)
- C. phi(mn) = mn
- D. phi(m * n) = phi(m) * phi(n) - 1
Correct answer: A. phi(mn) = phi(m) * phi(n)
The totient is multiplicative over coprime arguments, which is why sieving by prime factors works.
More Coding Interview Problems questions
- Problem: An undirected graph has vertices 0–7 and edges 0-1, 0-2, 1-2, 2-3, 4-5, 5-6, 6-4, 6-7. How many connected components contain at…
- Problem: Vertices 0–5 form a directed graph with arcs 0→1, 1→2, 2→3, 3→1, 3→4, 4→5, 5→4. Let S be the set of vertices reachable from 0…
- Problem: Kruskal's algorithm on the edges 0-1 (3), 1-2 (1), 0-2 (2), 2-3 (5), 1-3 (4), 3-4 (2), 2-4 (6) processes the edges in increasing…
- Problem: A tree has 7 nodes labelled 1–7 with edges 1-2, 1-3, 3-4, 3-5, 5-6, 5-7. Node 1 is the root. What is the depth of the deepest…
- Problem: Strings "axbycz" and "abc" are given. Count the subsequences of "axbycz" that equal "abc" (indices must be increasing, and…
- Problem: Starting with the list [1, 2, 3, 4, 5, 6], repeatedly remove every second element (keeping the first) until one element remains…