Expanding Can Be Tedious

The number

( 1 + 2 ) 27 \huge{(1+\sqrt{2})^{27}}

can be represented as x y + z x\sqrt{y} + z where x , y x,y and z z are positive integers.Find x + y + z x+y+z .


The answer is 18457556054.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

6 solutions

Discussions for this problem are now closed

Pi Han Goh
Apr 23, 2014

( 1 + 2 ) 27 = ( ( ( 1 + 2 ) 3 ) 3 ) 3 (1 + \sqrt 2)^{27} = \left ( \left ( (1 + \sqrt 2)^3 \right )^3 \right )^3

By binomial expansion, ( a + b 2 ) 3 = ( a 3 + 6 a b 2 ) + 2 ( 3 a 2 b + 2 b 3 ) (a + b \sqrt 2)^3 = (a^3 + 6ab^2) + \sqrt2 (3a^2 b + 2b^3 )

Let ( x n + 1 , y n + 1 ) = ( x n 3 + 6 x n y n 2 , 3 x n 2 y n + 2 y n 3 ) (x_{n+1}, y_{n+1}) = (x_n^3 + 6x_n y_n^2 , 3x_n^2 y_n + 2y_n^3 ) with ( x 0 , y 0 ) = ( 1 , 1 ) (x_0, y_0) = (1,1)

Then ( x 1 , y 1 ) = ( 7 , 5 ) , ( x 2 , y 2 ) = ( 1393 , 985 ) , ( x 3 , y 3 ) = ( 10812186007 , 7645370045 ) (x_1, y_1) = (7, 5), (x_2, y_2) = (1393, 985 ) , (x_3, y_3) = (10812186007,7645370045)

Hence, x + y + z = 10812186007 + 7645370045 + 2 = 18457556054 x + y + z = 10812186007 + 7645370045 + 2 = \boxed{18457556054}

Thaddeus Abiy
Apr 23, 2014

Let

t = 1 + 2 t=1+\sqrt{2}

t 2 = 3 + 2 2 = 2 ( 1 + 2 ) + 1 = 2 t + 1 t^2=3+2\sqrt{2}=2(1+\sqrt{2}) + 1=2t+1

t n + 2 = 2 t n + 1 + t n t^{ n+2 }=2t^{ n+1 }+t^{n}

t 2 = 2 t + 1 t^2=2t+1

t 3 = 5 t + 2 t^3=5t+2

t 4 = 12 t + 5 t^4=12t+5

t 5 = 29 t + 12 t^5=29t+12

We observe that

t n = a n t + a n 1 t^n=a_{n}t+a_{n-1}

where

a n = 2 a n 1 + a n 2 a_{n}=2a_{n-1}+a_{n-2}

for a 1 = 1 a_{1}=1 and a 2 = 2 a_{2}=2

Thus t 27 = a 27 t + a 26 t^{27}=a_{27}t+a_{26}

The recursive equation is similar to the Fibonacci equation and similar code can be written to get a n a_{n}

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
def A(n):
    if n <= 2:
        return n
    a , b = A(n/2 + 1) , A(n/2)
    if n % 2 == 1:
        return a*a + b*b
    else:
        return 2*b*(a - b)

def Coefficients(n):
    a,b=A(n),A(n-1)
    return a,a+b

print sum(Coefficients(27))+2

Running the code yields the answer

18457556054 \large{18457556054}

Look up fast fibonacci algorithms which do not calculate every single term like you did.

The 'standard' computing approach to calculate this quickly, is to repeatedly square and then multiply. Take a look at @Pi Han Goh 's solution, which does the cubing version.

Calvin Lin Staff - 7 years, 1 month ago

Yes,that is the quickest known Fibonacci algorithm. My previous code did unnecessary calculations. This new algorithm works by taking advantage of an expression based on the matrix identity of the Fibonacci sequence. Anyway, for this problem the expression becomes

A 2 n = 2 A n ( A n + 1 A n ) A_{2n}=2A_{n}(A_{n+1} - A_{n}) A 2 n + 1 = A n 2 + A n + 1 2 A_{2n+1}=A_{n}^2 + A_{n+1}^2

So A(n) becomes

1
2
3
4
5
6
7
8
def A(n):
    if n <= 2:
        return n
    a , b = A(n/2 + 1) , A(n/2)
    if n % 2 == 1:
        return a*a + b*b
    else:
        return 2*b*(a - b)

Thank you for telling me about the algorithm( Fast Doubling ).I didnt know it before. Also thanks for changing the title of the problem.I realized it was wrong after I posted it and was thinking about mailing you to change it.

Thaddeus Abiy - 7 years, 1 month ago

Good problem!

Carlos E. C. do Nascimento - 7 years, 1 month ago
Emanuel Saringan
Jun 1, 2014

I wrote this Java code to solve this problem:

public class Expanding {
    public static void main(String[] args) {
        long a = 1;
        long b = 1;
        for (int i = 1; i <= 26; i++) {
            long tempA = 2 * b + a;
            long tempB = b + a;

            a = tempA;
            b = tempB;
        }

        System.out.println(a + b + 2);
    }
}

It is astonishing to see that no body tried sage:

expand((1+sqrt(2))^27)

Returns

7645370045*sqrt(2) + 10812186007

Or Mathematica

Expand[(1 + Sqrt[2])^27]
= 10812186007 + 7645370045 Sqrt[2]

Bernardo Sulzbach - 6 years, 11 months ago
Bill Bell
Dec 25, 2014

It's inevitable that hackers will do something like this:

(We're lazy and consequently never learn much mathematics.)

Kenny Lau
Sep 5, 2014

java code:

public class brilliant201409061443{
    public static void main(String[] args){
        long x = 0;
        long y = 2;
        long z = 1;
        for(int i=0;i<27;i++){
            long new_x = z+x;
            long new_z = z+2*x;
            x = new_x;
            z = new_z;
        } // (x*sqrt(2)+z)(sqrt(2)+1) = (z+x)sqrt(2)+(z+2x)
        System.out.println(x+y+z);
    }
}

Output: 18457556054

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...