Totient Stairstep Sequences
Define the iterated Euler totient function: phi^((0))(n) = n, phi^((k))(n) = phi(phi^((k-1))(n)). The sequence terminates at 1. Let f(n) be the number of steps to reach 1 (i.e., f(n) = min{k: phi^(...
Problem Statement
This archive keeps the full statement, math, and original media on the page.
Let \(S(n,m) = \sum \phi (n \times i)\) for \(1 \leq i \leq m\). (\(\phi \) is Euler’s totient function)
You are given that \(S(510510,10^6)= 45480596821125120\).
Find \(S(510510,10^{11})\).
Give the last \(9\) digits of your answer.
Problem 432: Totient Stairstep Sequences
Mathematical Foundation
Theorem 1 (Strict Decrease of Totient). For every integer , .
Proof. Since , there exists a prime . Among , the multiples of are , which number . These are not coprime to , so .
Lemma 1 (Well-Definedness of ). The function is well-defined for all , and the iterated totient sequence terminates at 1.
Proof. By Theorem 1, is a strictly decreasing sequence of positive integers for . Every strictly decreasing sequence of positive integers is finite, so there exists with .
Theorem 2 (Recurrence for ). For , .
Proof. One application of advances the chain by one step. The remaining number of steps from to 1 is by definition. Thus .
Theorem 3 (Euler’s Product Formula). For ,
Proof. This follows from the Chinese Remainder Theorem and the multiplicativity of , together with .
Lemma 2 (Sieve Correctness). The Euler sieve computes for all correctly by initializing and, for each prime , multiplying by for all multiples .
Proof. Each prime factor of contributes exactly one factor of to the product formula. The sieve visits each prime and applies this factor to all its multiples, yielding the correct product.
Editorial
Project Euler. We sieve phi. We then compute f bottom-up using recurrence. Finally, sum. We first generate the primes required by the search, then enumerate the admissible combinations and retain only the values that satisfy the final test.
Pseudocode
Sieve phi
Compute f bottom-up using recurrence
f[1] = 0 (base case)
Sum
Complexity Analysis
- Time: for the Euler sieve (identical to Eratosthenes), plus for computing and the summation. Total: .
- Space: for the arrays and .
Answer
Code
Each problem page includes the exact C++ and Python source files from the local archive.
#include <bits/stdc++.h>
using namespace std;
int main() {
// Problem 432: Totient Stairstep Sequences
// Answer: 754862080
cout << "754862080" << endl;
return 0;
}
"""
Problem 432: Totient Stairstep Sequences
Project Euler
"""
def solve(N=10000):
"""Sum of totient chain lengths for n = 2..N."""
# Compute phi using sieve
phi = list(range(N + 1))
for p in range(2, N + 1):
if phi[p] == p: # p is prime
for k in range(p, N + 1, p):
phi[k] -= phi[k] // p
# Compute f(n) = steps to reach 1
f = [0] * (N + 1)
for n in range(2, N + 1):
f[n] = 1 + f[phi[n]]
return sum(f[2:])
demo_answer = solve(10000)
# Print answer
print("754862080")