// you’re reading...
1 Star2 Stars3 Stars4 Stars5 Stars (4 votes, average: 5.00 out of 5)
Loading...

Project Euler Solutions

Project Euler 318 Solution

Project Euler 318 Solution

Project Euler 318: Project Euler 318: Counting the number of consecutive nines at the beginning of the fractional part of (√p+√q)2n


Project Euler 318: Consider the real number √2+√3.

When we calculate the even powers of √2+√3
we get:

(√2+√3)2 = 9.898979485566356…
(√2+√3)4 = 97.98979485566356…
(√2+√3)6 = 969.998969071069263…
(√2+√3)8 = 9601.99989585502907…
(√2+√3)10 = 95049.999989479221…
(√2+√3)12 = 940897.9999989371855…
(√2+√3)14 = 9313929.99999989263…
(√2+√3)16 = 92198401.99999998915…

It looks like that the number of consecutive nines at the beginning of the fractional part of these powers is non-decreasing.

In fact it can be proven that the fractional part of (√2+√3)2n approaches 1 for large n.

Consider all real numbers of the form √p+√q with p and q positive integers and p<q, such that the fractional part
of (√p+√q)2n approaches 1 for large n.

Let C(p,q,n) be the number of consecutive nines at the beginning of the fractional part of
(√p+√q)2n.

Let N(p,q) be the minimal value of n such that C(p,q,n) ≥ 2011.

Find ∑N(p,q) for p+q ≤ 2011.

Project Euler 318 Solution

Runs < 0.470 seconds in Python 2.7.
#Project Euler Problem 318 Solution

from math import sqrt, log10, ceil
s, L = 0, 2011

for p in xrange(1, L):
    for q in xrange(p+1, L-p+1):
        c = p + q - 2*sqrt(p*q)
        if c < 1:
            s += ceil(-L / log10(c))

print "sum of N(p,q) for p+q <=", L, "is", int(s)
download arrowUse this link to get the Project Euler 318 Solution Python 2.7 source.

Answer

Slowly swipe from either end beginning with the white vertical bar to get an idea of the starting or ending digits. For less drama, just double click the answer area. The distance between the two bars will give you an idea of the magnitude. Touch devices can tap and hold the center of the box between the two bars and choose define to reveal the answer.
|709313889|

Afterthoughts

    No afterthoughts yet.
Project Euler 318 Solution last updated

Discussion

No comments yet.

Post a comment