**This is our solution and implementation to problem #66 on Project Euler.**

Our code is written in TypeScript, a language which is built on-top of JavaScript and transpiles to it. We've included the problem statement, our code (which is commented for greater clarity), our video which outlines our analysis and implementation approach, and the solution + how long it took to calculate it.

**Note:** the code and contents here might be slightly different than what is in the video. We've made some improvements to some of the code since recording.

If you would like to view the original problem and solve it, please visit: Diophantine Equation on Project Euler. If you're having trouble solving this problem, or are just curious to see how others have solved it, feel free to take a look, but please put solid effort into solving this before viewing the actual solution to the problem.

### Problem Statement

Consider quadratic Diophantine equations of the form:

*x*^{2} – D*y*^{2} = 1

For example, when D=13, the minimal solution in *x* is 649^{2} – 13×180^{2} = 1.

It can be assumed that there are no solutions in positive integers when D is square.

By finding minimal solutions in *x* for D = {2, 3, 5, 6, 7}, we obtain the following:

3^{2} – 2×2^{2} = 1

2^{2} – 3×1^{2} = 1

9^{2} – 5×4^{2} = 1

5^{2} – 6×2^{2} = 1

8^{2} – 7×3^{2} = 1

Hence, by considering minimal solutions in *x* for D ≤ 7, the largest *x* is obtained when D=5.

Find the value of D ≤ 1000 in minimal solutions of *x* for which the largest value of *x* is obtained.

### Our Solution

Our solution is given in the TypeScript files below. This solution uses more than one code file. Some solutions use utilities which were created and enhanced while working on this and previous Project Euler problems. Some code in the utilities files might not be used in this particular problem.

### Results

This implementation found the solution in **561ms**.

If you would like to view the answer, click below to reveal. Please consider reviewing the implementation and trying to code your own solution before viewing the answer.

## View Answer

The answer is

**661.**

All of our solutions are hosted on GitHub. The code on this page was pulled from the repo and the solution and execution time were calculated based on that code.