I am solving SPOJ problem FLIB and I have tried implementing this using Maps like this –
long long FiboSum(long long n) {
if(n==1||n==0) return n;
if(fiboDict.count(n)) return (long long) fiboDict.at(n);
if(n%2==0) {
//calculate term -- value to that key
fiboDict.insert(pair<long,long>(n,term));
}
else {
//calculate term
fiboDict.insert(pair<long,long>(n,term));
}
return (long long) fiboDict.at(n);
}
fiboDict is the map, but the problem needs me to calculate for ( 0 <= n < 2^51) but KEY value can’t hold such high values, and I am getting Error
terminate called after throwing an instance of 'std::out_of_range' what():
map::at
How could I make it hold large values? or If there is alternative then please suggest.
Why dont you make map of :
then?