Let
F
n
be the
n
th Fibonacci number, where
F
1
=
F
2
=
1
.
Also, let
S
=
n
=
1
∑
∞
F
n
1
.
Use a program to find
⌊
1
0
0
0
0
×
S
⌋
.
Note:
F
n
is defined so that
F
n
=
F
n
−
1
+
F
n
−
2
,
n
∈
Z
.
Also note:
⌊
x
⌋
is defined as the greatest integer less than or equal to
x
.
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.
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 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 th Fibonacci number, 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 digits of S , since it is a finite sum whereas 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 3 8 approximations of S . We can see that the values of the first 5 digits do not change at all after the 2 3 r d approximation. Therefore, the value of ⌊ 1 0 0 0 0 × S ⌋ is unchanged after the 2 3 r d approximation. So our first 5 digits are 3 . 3 5 9 8 . Multiplying by 1 0 0 0 0 gives ⌊ 1 0 0 0 0 × S ⌋ = 1 0 0 0 0 × 3 . 3 5 9 8 = 3 3 5 9 8
The number 3 . 3 5 9 8 8 5 6 6 6 2 4 . . . is known as the Reciprocal Fibonacci Constant. One of my favorite properties of the constant is that it contains the early sequence of digits, 6 6 6 , which is related to Fibonacci numbers in that − 2 sin ( 6 6 6 ∘ ) = 2 1 + 5 = ϕ , the golden ratio.
Python:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
|
Problem Loading...
Note Loading...
Set Loading...