Luís Ramalho

Product, Engineering, Business & Management

Twitter LinkedIn Github Stackoverflow Youtube

Project Euler — Problem 57

Square root convergents is a problem in which one must find how many fractions of the square root of 2 contain a numerator with more digits than denominator.

Since we are dealing with big numbers, we should use BigIntegers. Then, I looked for a pattern since we are given the first 8 iterations.

Respectively: $$\frac{3}{2}$$, $$\frac{7}{5}$$, $$\frac{17}{12}$$, $$\frac{41}{29}$$, $$\frac{99}{70}$$, $$\frac{239}{169}$$, $$\frac{577}{408}$$, $$\frac{1393}{985}$$

I found one that applied for both the numerator and denominator:

Afterwards, it was trivial to code the solution:

The full solution can be found here.