2018-09-30 22:01:58 +00:00
---
id: 5900f4421000cf542c50ff55
title: 'Problem 214: Totient Chains'
2020-11-27 18:02:05 +00:00
challengeType: 5
2019-08-05 16:17:33 +00:00
forumTopicId: 301856
2021-01-13 02:31:00 +00:00
dashedName: problem-214-totient-chains
2018-09-30 22:01:58 +00:00
---
2020-11-27 18:02:05 +00:00
# --description--
2021-07-15 07:20:31 +00:00
Let $φ$ be Euler's totient function, i.e. for a natural number $n$, $φ(n)$ is the number of $k$, $1 ≤ k ≤ n$, for which $gcd(k,n) = 1$.
2018-09-30 22:01:58 +00:00
2021-07-15 07:20:31 +00:00
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:
2018-09-30 22:01:58 +00:00
2021-07-15 07:20:31 +00:00
$$\begin{align}
5,4,2,1 & \\\\
7,6,2,1 & \\\\
8,4,2,1 & \\\\
9,6,2,1 & \\\\
10,4,2,1 & \\\\
12,4,2,1 & \\\\
14,6,2,1 & \\\\
18,6,2,1 &
\end{align}$$
2018-09-30 22:01:58 +00:00
Only two of these chains start with a prime, their sum is 12.
2021-07-15 07:20:31 +00:00
What is the sum of all primes less than $40\\,000\\,000$ which generate a chain of length 25?
2018-09-30 22:01:58 +00:00
2020-11-27 18:02:05 +00:00
# --hints--
2018-09-30 22:01:58 +00:00
2021-07-15 07:20:31 +00:00
`totientChains()` should return `1677366278943` .
2018-09-30 22:01:58 +00:00
2020-11-27 18:02:05 +00:00
```js
2021-07-15 07:20:31 +00:00
assert.strictEqual(totientChains(), 1677366278943);
2018-09-30 22:01:58 +00:00
```
2020-11-27 18:02:05 +00:00
# --seed--
2018-09-30 22:01:58 +00:00
2020-11-27 18:02:05 +00:00
## --seed-contents--
2018-09-30 22:01:58 +00:00
```js
2021-07-15 07:20:31 +00:00
function totientChains() {
2020-09-15 16:57:40 +00:00
2018-09-30 22:01:58 +00:00
return true;
}
2021-07-15 07:20:31 +00:00
totientChains();
2018-09-30 22:01:58 +00:00
```
2020-11-27 18:02:05 +00:00
# --solutions--
2018-09-30 22:01:58 +00:00
```js
// solution required
```