Jump to content

Fibonacci sequence: Difference between revisions

m
→‎Arbitrary Precision: accidently omitted line in last edit
m (→‎Arbitrary Precision: streamline code, remove Linq requirement.)
m (→‎Arbitrary Precision: accidently omitted line in last edit)
Line 2,168:
public static BigInteger Fsl(int n)
{
if (n < 2) return n;
int n2 = n >> 1; if (!sl.ContainsKey(n2)) sl.Add(n2, Fsl(n2));
if ((n & 1) != 1)
Line 2,192 ⟶ 2,193:
int num = 2_000_000;
DateTime st = DateTime.Now;
sl.Add(0, 0); sl.Add(1, 1);
BigInteger v = Fsl(num);
Console.WriteLine("{0:n3} ms to calculate the {1:n0}th Fibonacci number,",
Line 2,214:
}</lang>
{{out}}
<pre>176175.510416 ms to calculate the 2,000,000th Fibonacci number,
4.720651 seconds to convert to a string.
number of digits is 417975
partial: 53129491750764154305166065450382516...91799493108960825129188777803453125</pre>
Cookies help us deliver our services. By using our services, you agree to our use of cookies.