Problem #69 Difficulty: 10%

Totient Maximum

Solution Language: Java

Problem Statement

Euler’s Totient function, φ(n) [sometimes called the phi function], is used to determine the number of numbers less than n which are relatively prime to n. For example, as 1, 2, 4, 5, 7, and 8, are all less than nine and relatively prime to nine, φ(9)=6.

nRelatively Primeφ(n)n/φ(n)
2112
31,221.5
41,322
51,2,3,441.25
61,523
71,2,3,4,5,661.1666…
81,3,5,742
91,2,4,5,7,861.5
101,3,7,942.5

It can be seen that n=6 produces a maximum n/φ(n) for n ≤ 10.

Find the value of n ≤ 1,000,000 for which n/φ(n) is a maximum.

Approach

The solution involves:

  1. Recognizing that n/φ(n) is maximized when n has many small prime factors
  2. The answer is the product of consecutive primes: 2 × 3 × 5 × 7 × 11 × 13 × 17
  3. Finding the largest primorial (product of consecutive primes) ≤ 1,000,000
  4. Alternatively, computing φ(n) for all n and finding the maximum ratio