Function fibonacci when n>93

I have a problem with function fibonacci when n>93.The value after that
is incorrect.I use unsigned long long or unsigned __int64 to identify the variable but it doesn't work!!!.

This is some code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
unsigned __int64 fib2 (unsigned __int64 n )
{
  unsigned __int64 x;
  static unsigned __int64 save[45];

  if ( save[n] != 0 )
    return save[n];
  else if ( n < 2 )
    x = n;
  else
    x = fib2 ( n - 1 ) + fib2 ( n - 2 );

  return save[n] = x;
}
What do you use save for? I don't really see it.

2^64-1 = 18,446,744,073,709,551,615
fibonacci94 = 19,740,274,219,868,223,167

EDIT: And calculating fibonacci iteratively rather than recursively is faster, more efficient, and will never produce a stack overflow.
Last edited on
Thanks but I don't figure out how to write a program.
Cloude you write some example for me. Thanks!!!
I suppose save[] is used to hold previously calculated Fibonacci numbers, in which case you're writing beyond array limits for n >= 45. Not good.

Apart from using save[], your code looks OK (apart from the things Helios had to say about iteration vs. recursion)
hello zewei
why don't you divede the resust by the [b]linked list[/b],look like :
from... 123456789 ...to ...123- 456 -789 -...by the LL.
ONE of part add 3 number an it is verry easy to count :add divide ,etc...
form part to part it is added to it .
SOORY, my english is too bad to explain to all of you guess my idea.
Topic archived. No new replies allowed.