| 
									
										
										
										
											2018-09-30 23:01:58 +01:00
										 |  |  | --- | 
					
						
							|  |  |  | id: 5900f4421000cf542c50ff55 | 
					
						
							|  |  |  | challengeType: 5 | 
					
						
							|  |  |  | title: 'Problem 214: Totient Chains' | 
					
						
							|  |  |  | --- | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ## Description
 | 
					
						
							|  |  |  | <section id='description'> | 
					
						
							|  |  |  | 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. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 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,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 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 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? | 
					
						
							|  |  |  | </section> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ## Instructions
 | 
					
						
							|  |  |  | <section id='instructions'> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | </section> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ## Tests
 | 
					
						
							|  |  |  | <section id='tests'> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ```yml | 
					
						
							| 
									
										
										
										
											2018-10-04 14:37:37 +01:00
										 |  |  | tests: | 
					
						
							|  |  |  |   - text: <code>euler214()</code> should return 1677366278943. | 
					
						
							| 
									
										
										
										
											2018-10-20 21:02:47 +03:00
										 |  |  |     testString: assert.strictEqual(euler214(), 1677366278943, '<code>euler214()</code> should return 1677366278943.'); | 
					
						
							| 
									
										
										
										
											2018-09-30 23:01:58 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | ``` | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | </section> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ## Challenge Seed
 | 
					
						
							|  |  |  | <section id='challengeSeed'> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <div id='js-seed'> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ```js | 
					
						
							|  |  |  | function euler214() { | 
					
						
							|  |  |  |   // Good luck! | 
					
						
							|  |  |  |   return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | euler214(); | 
					
						
							|  |  |  | ``` | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | </div> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | </section> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ## Solution
 | 
					
						
							|  |  |  | <section id='solution'> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ```js | 
					
						
							|  |  |  | // solution required | 
					
						
							|  |  |  | ``` | 
					
						
							|  |  |  | </section> |