The number
( 1 + 2 ) 2 7
can be represented as x y + z where x , y and z are positive integers.Find x + y + z .
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.
Let
t = 1 + 2
t 2 = 3 + 2 2 = 2 ( 1 + 2 ) + 1 = 2 t + 1
t n + 2 = 2 t n + 1 + t n
t 2 = 2 t + 1
t 3 = 5 t + 2
t 4 = 1 2 t + 5
t 5 = 2 9 t + 1 2
We observe that
t n = a n t + a n − 1
where
a n = 2 a n − 1 + a n − 2
for a 1 = 1 and a 2 = 2
Thus t 2 7 = a 2 7 t + a 2 6
The recursive equation is similar to the Fibonacci equation and similar code can be written to get a n
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
Running the code yields the answer
1 8 4 5 7 5 5 6 0 5 4
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.
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 2 n + 1 = A n 2 + A n + 1 2
So A(n) becomes
1 2 3 4 5 6 7 8 |
|
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.
Good problem!
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]
It's inevitable that hackers will do something like this:
(We're lazy and consequently never learn much mathematics.)
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
Problem Loading...
Note Loading...
Set Loading...
( 1 + 2 ) 2 7 = ( ( ( 1 + 2 ) 3 ) 3 ) 3
By binomial expansion, ( a + b 2 ) 3 = ( a 3 + 6 a b 2 ) + 2 ( 3 a 2 b + 2 b 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 ) with ( x 0 , y 0 ) = ( 1 , 1 )
Then ( x 1 , y 1 ) = ( 7 , 5 ) , ( x 2 , y 2 ) = ( 1 3 9 3 , 9 8 5 ) , ( x 3 , y 3 ) = ( 1 0 8 1 2 1 8 6 0 0 7 , 7 6 4 5 3 7 0 0 4 5 )
Hence, x + y + z = 1 0 8 1 2 1 8 6 0 0 7 + 7 6 4 5 3 7 0 0 4 5 + 2 = 1 8 4 5 7 5 5 6 0 5 4