using System.Collections.Generic;
namespace Training_Project
static Dictionary<int, BigInteger> _fibonacciOfNumber = new();
static int _callCountWithCaching = 0;
static int _callCountWithoutCaching = 0;
static void Main(string[] args)
var fibonacciWithCaching = FibWithCaching(number);
Console.WriteLine($"With caching: Fibonacci({number}) = {fibonacciWithCaching}. Method calls: {_callCountWithCaching}");
var fibonacciWithoutCaching = FibWithoutCaching(number);
Console.WriteLine($"Without caching: Fibonacci({number}) = {fibonacciWithoutCaching}. Method calls: {_callCountWithoutCaching}");
static BigInteger FibWithCaching(int n)
if (!_fibonacciOfNumber.ContainsKey(n))
_fibonacciOfNumber[n] = FibWithCaching(n - 1) + FibWithCaching(n - 2);
return _fibonacciOfNumber[n];
static BigInteger FibWithoutCaching(int n)
_callCountWithoutCaching++;
return FibWithoutCaching(n - 1) + FibWithoutCaching(n - 2);