Fibonacci, inverted

Let F n F_n be the n n th Fibonacci number, where F 1 = F 2 = 1. F_1 = F_2 = 1. Also, let S = n = 1 1 F n . S = \sum_{n=1}^{\infty} \frac{1}{F_n}. Use a program to find 10000 × S . \lfloor 10000\times S\rfloor .
Note: F n F_n is defined so that F n = F n 1 + F n 2 , n Z . F_n = F_{n-1} + F_{n-2},\ n \in \mathbb{Z}.
Also note: x \lfloor x \rfloor is defined as the greatest integer less than or equal to x . x.


The answer is 33598.

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.

3 solutions

Alex Li
Feb 16, 2015
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Collections;
import java.util.Scanner;
import java.io.File;
public class x
{
    public static double Fibby(double x)
    {
        double y = Math.sqrt(5);
        return 
        (Math.pow((1+y),x)-Math.pow((1-y),x))/(Math.pow(2,x)*Math.sqrt(5));
        //Binet's Formula
    }
    public static void main(String[] args) throws IOException
    {
        double x = 0;
        for(int i = 1; i<1000; i++) //999 should be enough for our purposes
        {
            x+=1/(Fibby(i)+0.0);
        }
        System.out.println(x);
    }
}

Caleb Townsend
Feb 9, 2015

First, note that we don't necessarily need a program to find the answer, but it will be very tedious (and possibly difficult) to do by hand. The solution is to first define a fibonacci method to find the n n th Fibonacci number. The method I use here is the (horribly inefficient) recursive method.

public static int fibonacci(int n)
{
    if (n == 0)
        return 0;
    else if (n == 1)
        return 1;
    else
        return (fibonacci(n-1) + fibonacci(n-2));
}

This gives us the n n th Fibonacci number, F n . F_n. Next we need our main method to compute the sum, so here's a hypothetical method:

public static void main(String[] args)
{
    double sum;
    for (int n = 1; n < 20; n++)
    {
        sum += 1.0 / (double)(fibonacci(n));
    }
    System.out.println(sum);
}

The main problem is that there's no guarantee this will accurately give the first 5 5 digits of S , S, since it is a finite sum whereas S S is a sum of infinitely many terms. To make sure we have the correct approximation, we need to change the main method.

public static void main(String[] args)
{
    double sum;
    for (int i = 2; i < 40; i++)
    {
        for (int n = 1; n < i; n++)
        {
            sum += 1.0 / (double)(fibonacci(n));
        }
    }
    System.out.println(sum);
}

This prints out 38 38 approximations of S . S. We can see that the values of the first 5 5 digits do not change at all after the 2 3 r d 23^{rd} approximation. Therefore, the value of 10000 × S \lfloor 10000 \times S \rfloor is unchanged after the 2 3 r d 23^{rd} approximation. So our first 5 digits are 3.3598. 3.3598. Multiplying by 10000 10000 gives 10000 × S = 10000 × 3.3598 = 33598 \lfloor 10000 \times S\rfloor = 10000 \times 3.3598 = \boxed{33598}

The number 3.35988566624... 3.35988566624 ... is known as the Reciprocal Fibonacci Constant. One of my favorite properties of the constant is that it contains the early sequence of digits, 666 666 , which is related to Fibonacci numbers in that 2 sin ( 66 6 ) = 1 + 5 2 = ϕ , -2\sin (666^\circ) = \frac{1+\sqrt{5}}{2} = \phi, the golden ratio.

Brock Brown
Feb 21, 2015

Python:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
from fractions import Fraction as frac
from math import floor
memo = {1:1,2:1}
def fib(n):
    if n in memo:
        return memo[n]
    memo[n] = fib(n-1)+fib(n-2)
    return memo[n]
memo2 = {1:frac(1,fib(1))}
def s(n):
    if n in memo2:
        return memo2[n]
    memo2[n] = s(n-1)+frac(1,fib(n))
    return memo2[n]
infinity = 200
for i in xrange(1, infinity):
    fib(i), s(i)
print float(s(infinity))
print floor(10000*s(infinity))

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...