I wrote the following code to find the 1500000th Fibonacci number(Please ignore horrible indenting, I wrote this in about 2 minutes). I need it as a string. This should, hypothetically work:
#include <cstdlib>
#include <iostream>
#include <sstream>
int i;
int b=1;
int c=2;
using namespace std;
int main(int argc, char *argv[])
{
int fib=1500000;
for (i=1;i<fib-3;i++){
c=b+c;
b=c-b;
}
stringstream ss;
ss << c;
string d=ss.str();
cout << d << endl;
system("PAUSE");
return EXIT_SUCCESS;
}
It goes through the process 1500000-3 times(It goes over by 3 numbers every time) I understand that the problem is that the number is to big to be contained as an int. Is there any way for me to store it without containing it as an int or file(Since that would be grossly inefficient)? If so, how would I do it?
Use a Bignum library.