I was trying to find find nth fibonacci number mod 100000 where n can be up to 5000000.
Here is my code :
#define max_n 5000000
int mod = 100000;
int memo[max_n + 5];
int fib (int n)
{
if (n == 1)
return 0;
if (n == 2)
return 1;
if (memo[n] > 0)
return memo[n];
memo[n]=(fib(n-1) + fib(n-2))%mod;
return memo[n];
}
But when i run the code. it gives runtime error . Please help
In main :
#include <iostream>
using namespace std;
int main()
{
int n, i;
for (i = max_n; i >= 1 ;i--)
{
fib (i);
}
cin >> n;
cout << memo[n] << endl;
return 0;
}