fibonacci numbers

Does my logic make sense?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
   
// What is the index of the first term in the Fibonacci sequence to contain 
// 1000 digits?

#include <iostream>
#include <math.h>

int main(int argc, const char * argv[])
{
    long double fibonacciRatio = (1.618);
    // d = b log a where d is number of digits b is power and a is base.
    // digits = 999 since log is base 10
    double power = 999/log10(fibonacciRatio);
    std::cout << power << " ";
    // add one to power for beginning ratio size
    power++;
    std::cout << power;
    // enter both to check
    return 0;
}


I came up with what i thought was an inventive way to tackle this problem and my solution gives me the right answer but I can't help but feel like maybe I just got lucky. Gave me 4780.4 and 4781.4. Rounded both, 4782 was right.
Last edited on
Topic archived. No new replies allowed.