Must we do it recursively?

Find the first 10 digits of the ( 1 0 12 ) th ({10^{12}}) ^\text{th} Fibonacci number , where F 0 = 0 , F 1 = 1 F_0 = 0,\,F_1=1 .


Inspiration .


The answer is 4258422688.

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.

1 solution

First Last
Dec 7, 2016

The code below uses Binet's Formula for F n = ( 1 + 5 2 ) n ( 1 5 2 ) n 5 F_n = \displaystyle\frac{\big( \frac{1+\sqrt{5}}{2}\big)^n-\big( \frac{1-\sqrt{5}}{2}\big)^n}{\sqrt{5}}

and the fact that ( 1 5 2 ) n \displaystyle\big( \frac{1-\sqrt{5}}{2}\big)^n is essentially 0 at n = 1 0 12 n = 10^{12}

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
int main(){@autoreleasepool{
        long double five = sqrtl(5) ;
        long double number = powl(10,12)*log10l((1+five)/2) ;
        number -= log10l(five) ;

        number = number - floorl(number) ;

        number += 9 ;

        NSLog(@"%.21Lg", powl(10,number)) ;

    }
    return 0;
}

Also note that for number n in base 10, the number of digits is log 10 n \log_{10}{n} and the first digits are representative of your precision with 1 0 ( log 10 n ) log 10 n \displaystyle 10^{( \log_{10}{n}) - \lfloor\log_{10}{n}\rfloor}

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...