Project Euler problem 69

February 28th, 2009 at 5:55 pm

Problem 69 is a really nice one. I looked at it, and immediately it seemed that brute-forcing is not required here. Yeah, Ron, I know it took you 35.671 ms to brute-force it :-) , but here’s a nicer mathematical solution without programming at all:

A formula to compute \varphi(n) is:

\varphi(n)= n \cdot \prod_{p|n} \left( 1-\frac{1}{p} \right)

Where p are the distinct primes dividing n. To minimize n / \varphi(n) we see that n should have as many prime factors as possible, and the smaller they are, the better.

Intuitively, if n has a prime factor p, then every p-th number upto n is not co-prime with n. Therefore, it would be great if every 2nd, 3rd, 5th etc. number were not co-prime with n, this would leave very few numbers that are co-prime with it, thus minimizing n / \varphi(n).

So, to solve it, find a number that’s a multiple of as many small primes as possible and is still less than 1,000,000

Related posts:

  1. Project Euler problem 26
  2. Project Euler problem 12
  3. Project Euler problem 43
  4. Project Euler problem 104
  5. Project Euler problem 66 and continued fractions

3 Responses to “Project Euler problem 69”

  1. ripper234No Gravatar Says:

    Nice method, how many milliseconds ? :)

  2. DiegoNo Gravatar Says:

    The problem asks to minimize the ratio.

  3. DiegoNo Gravatar Says:

    Sorry! I repeated the mistake :P . The problem asks to MAXIMIZE the ratio.

Leave a Reply

To post code with preserved formatting, enclose it in `backticks` (even multiple lines)