Advertisement
Guest User

Untitled

a guest
Apr 29th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Numerics;
  5.  
  6. class Solution {
  7. static void Main(String[] args) {
  8. int[] arr = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
  9. BigInteger t1 = new BigInteger(arr[0]);
  10. BigInteger t2 = new BigInteger(arr[1]);
  11. int n = arr[2];
  12.  
  13. Dictionary<int, BigInteger> dict = new Dictionary<int, BigInteger>();
  14. dict.Add(1, t1);
  15. dict.Add(2, t2);
  16.  
  17. Console.WriteLine(fib(n, dict));
  18. }
  19.  
  20. static BigInteger fib(int n, Dictionary<int, BigInteger> dict) {
  21. if(dict.ContainsKey(n))
  22. return dict[n];
  23.  
  24. BigInteger tn = fib(n-2, dict) + fib(n-1, dict) * fib(n-1, dict);
  25. dict.Add(n, tn);
  26. return tn;
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement