Fibonacci sequence: Difference between revisions

Content deleted Content added
Ce (talk | contribs)
→‎{{header|Logo}}: +Mathematica
→‎{{header|Java}}: Added analytic method
Line 327: Line 327:
if(n <= 2) return 1;
if(n <= 2) return 1;
return recFibN(n-1) + recFibN(n-2);
return recFibN(n-1) + recFibN(n-2);
}</java>
===Analytic===
This method works up to the 92<sup>nd</sup> Fibonacci number. After that, it goes out of range.
<java>public static long anFibN(long n){
double p= (1 + Math.sqrt(5)) / 2;
double q= 1 / p;
return (long)((Math.pow(p, n) + Math.pow(q, n)) / Math.sqrt(5));
}</java>
}</java>