Project Euler problem 69
February 28th, 2009 at 5:55 pmProblem 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
is:

Where p are the distinct primes dividing n. To minimize
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
.
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:

March 1st, 2009 at 00:43
Nice method, how many milliseconds ?
April 30th, 2012 at 03:56
The problem asks to minimize the ratio.
April 30th, 2012 at 03:57
Sorry! I repeated the mistake
. The problem asks to MAXIMIZE the ratio.