Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Numerics;
- class Solution {
- static void Main(String[] args) {
- int[] arr = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
- BigInteger t1 = new BigInteger(arr[0]);
- BigInteger t2 = new BigInteger(arr[1]);
- int n = arr[2];
- Dictionary<int, BigInteger> dict = new Dictionary<int, BigInteger>();
- dict.Add(1, t1);
- dict.Add(2, t2);
- Console.WriteLine(fib(n, dict));
- }
- static BigInteger fib(int n, Dictionary<int, BigInteger> dict) {
- if(dict.ContainsKey(n))
- return dict[n];
- BigInteger tn = fib(n-2, dict) + fib(n-1, dict) * fib(n-1, dict);
- dict.Add(n, tn);
- return tn;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement