0

What is the first term in the Fibonacci sequence to contain 1000 digits?

so i made a program that finds the fibonocci's sequence (fs).

I tried to do it recursively but it takes too long for big numbers. so i made a manual one.

BUt as i count how many digits there are for each (fs). a problem exist. After F(1476)--which has 309 digits, the program stops suddenly. I think its because of memory space or something. Any ways, this is why I turned to you. any help

here is my code

```
#include<iostream>
#include<fstream>
#include<iomanip>
#include<cmath>
using namespace std;
int countdigits(unsigned long double x)
{
int count(0);
while(x>.99999999999999)
{
x/=10;
count++;
}
return count;
}
int main(){
unsigned long double result = 0.0;
unsigned long double x = 1.0;
unsigned long double y = 1.0;
unsigned long double result2 = 0.0;
int count(0);
for(int i = 3;;i++)
{
result = x+y;
y = x;
x = result;
result2 = result;
cout<<setprecision(10)<<"F of "<<i<<" is : "<<result/1000000<<" count is : "<<countdigits(result2)<<endl;
if(( countdigits(result2) == 1000 ) )
{
cin.get();
}
}
return 0;
}
```

try running the program to get a better understanding , and then maybe you can help be better. thanks :)