package hackerrank;

import java.util.Scanner;

/**
 * https://www.hackerrank.com/challenges/fibonacci-modified
 */
public class FibonacciModified {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // TODO
    }
}

@@ -14,16 +14,93 @@
 rrank;%0A%0A
+import java.math.BigInteger;%0Aimport java.util.HashMap;%0Aimport java.util.Map;%0A
 import j
@@ -228,108 +228,1009 @@
    p
-ublic static void main(String%5B%5D args) %7B%0A        Scanner in = new Scanner(System.in);%0A        // TODO
+rivate static BigInteger fibonacciModified(int t1, int t2, int n) %7B%0A        return fibMod(BigInteger.valueOf(t1), BigInteger.valueOf(t2), n,%0A            new HashMap%3C%3E());%0A    %7D%0A%0A    private static BigInteger fibMod(BigInteger t1, BigInteger t2, int n,%0A                                     Map%3CInteger, BigInteger%3E memo) %7B%0A        if (n == 1) %7B%0A            return t1;%0A        %7D%0A        if (n == 2) %7B%0A            return t2;%0A        %7D%0A        if (memo.containsKey(n)) %7B%0A            return memo.get(n);%0A        %7D%0A        BigInteger a = fibMod(t1, t2, n - 2, memo);%0A        BigInteger b = fibMod(t1, t2, n - 1, memo);%0A        BigInteger bSquared = b.multiply(b);%0A        BigInteger result = a.add(bSquared);%0A        memo.put(n, result);%0A        return result;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        Scanner in = new Scanner(System.in);%0A        int t1 = in.nextInt();%0A        int t2 = in.nextInt();%0A        int n = in.nextInt();%0A        System.out.println(fibonacciModified(t1, t2, n));
 %0A   

Solve Fibonacci Modified