## It is possible to show that the square root of two can be expressed as an infinite continued fraction.

$\sqrt 2 =1+ \frac 1 {2+ \frac 1 {2 +\frac 1 {2+ \dots}}}$

By expanding this for the first four iterations, we get:

$1 + \frac 1 2 = \frac 32 = 1.5$

$1 + \frac 1 {2 + \frac 1 2} = \frac 7 5 = 1.4$

$1 + \frac 1 {2 + \frac 1 {2+\frac 1 2}} = \frac {17}{12} = 1.41666 \dots$

$1 + \frac 1 {2 + \frac 1 {2+\frac 1 {2+\frac 1 2}}} = \frac {41}{29} = 1.41379 \dots$

The next three expansions are $\frac {99}{70}$, $\frac {239}{169}$, and $\frac {577}{408}$, but the eighth expansion, $\frac {1393}{985}$, is the first example where the number of digits in the numerator exceeds the number of digits in the denominator.

In the first one-thousand expansions, how many fractions contain a numerator with more digits than the denominator?

### This mathematics problem can be solved by understanding the sequence of the numerators and denominators in the continued fraction expansion for the square root of two.

Looking closely, you can notice that the numerators and denominators follow a pattern:

– Numerator: 1, 3, 7, 17, 41, 99, 239, 577, 1393, …

– Denominator: 2, 5, 12, 29, 70, 169, 408, 985, …

Each term in the numerator and denominator is two times the previous term plus its previous term (for example, 7 = 2*3 + 1, 17 = 2*7 + 3…). This sequence is known as a “recurrence relation” and is defined by the formula:

– aₙ = 2*aₙ₋₁ + aₙ₋₂, for n ≥ 2,

with initial terms a₀ = 1 and a₁ = 2.

It now becomes a programming problem, where we generate the first 1000 fractions and count how many times the number of digits in the numerator exceeds the number of digits in the denominator.

Let’s write a Python pseudocode for this:

“`python

a, b = 3, 2 # Initial terms for numerator and denominator respectively.

count = 0

for _ in range(1000):

# Check if the number of digits in ‘a’ is greater than the number of digits in ‘b’.

if len(str(a)) > len(str(b)):

count += 1

# Generate the next term in the sequence for ‘a’ and ‘b’.

a, b = 2*a + b, a + b

print(count)

“`

This code calculates the first 1000 expansions, and increments the count only when the numerator has more digits than the denominator. Running this code will give you the desired answer.

It’s important to note that you need at least a fair understanding of programming to solve this problem. But understanding the recurring nature of the fractions helps you to attempt this question even if you cannot code it by yourself.

Given the problem definition, this approach should work since it follows the required pattern and considers the terms in the correct order (with numerator slightly ahead of denominator). However, it’s always good to program defensively and consider edge cases whenever you’re solving real-world problems.

##### More Answers:

Poker HandsLychrel Numbers

Powerful Digit Sum