Project Euler > Problem 110 > Diophantine reciprocals II (Java Solution)

Problem:

In the following equation x, y, and n are positive integers.

1

x
+
1

y
=
1

n

It can be verified that when n = 1260 there are 113 distinct solutions and this is the least value of n for which the total number of distinct solutions exceeds one hundred.

What is the least value of n for which the number of distinct solutions exceeds four million?

NOTE: This problem is a much more difficult version of problem 108 and as it is well beyond the limitations of a brute force approach it requires a clever implementation.


Solution:

142913828922

Code:
The solution may include methods that will be found here: Library.java .

public interface EulerSolution{

public String run();

}
/* 
* Solution to Project Euler problem 10
* By Nayuki Minase
*
* http://nayuki.eigenstate.org/page/project-euler-solutions
* https://github.com/nayuki/Project-Euler-solutions
*/


public final class p010 implements EulerSolution {

public static void main(String[] args) {
System.out.println(new p010().run());
}


private static final int LIMIT = 2000000;

public String run() {
long sum = 0;
for (int p : Library.listPrimes(LIMIT - 1))
sum += p;
return Long.toString(sum);
}

}

No comments:

Post a Comment