← Complete problem index

PROJECT EULER · #0214

Totient Chains

Statement only · SolvedOriginal problem ↗

Let ϕ be Euler's totient function, i.e. for a natural number n, ϕ(n) is the number of k, 1kn, for which gcd(k,n)=1.

By iterating ϕ, each positive integer generates a decreasing chain of numbers ending in 1.
E.g. if we start with 5 the sequence 5,4,2,1 is generated.
Here is a listing of all chains with length 4:

5,4,2,17,6,2,18,4,2,19,6,2,110,4,2,112,4,2,114,6,2,118,6,2,1

Only two of these chains start with a prime, their sum is 12.

What is the sum of all primes less than 40000000 which generate a chain of length 25?

Write-up coming later

The complete problem is available here. An approach, code, and answer will be added later.