@@ -0,0 +1,2023 @@
+//https://www.hackerrank.com/challenges/red-john-is-back%0Aimport java.io.*;%0Aimport java.util.*;%0A%0Apublic class Solution %7B%0A    %0A    private final static byte MAX_N = 40;%0A    private final static int MAX_WAYS = 217286;%0A    %0A    public static void main(String%5B%5D args) throws IOException %7B%0A        %0A        //INIT%0A        final StringBuffer sb = new StringBuffer();%0A        final int%5B%5D mem = new int%5BMAX_N+1%5D;%0A        for(byte i = 0; i %3C 4; mem%5Bi++%5D = 1)%7B%7D%0A        int curMax = 3;%0A        final int%5B%5D primes = getPrimes(MAX_WAYS);%0A        %0A        //INPUT%0A        final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));%0A        for(byte T = Byte.parseByte(br.readLine()); T %3E 0; --T)%7B%0A            final byte N = Byte.parseByte(br.readLine());%0A            %0A            //SOLVE%0A            while (curMax %3C N)%7B%0A                mem%5BcurMax+1%5D = mem%5BcurMax%5D + mem%5BcurMax - 3%5D;%0A                ++curMax;%0A            %7D%0A            %0A            int i = Arrays.binarySearch(primes, mem%5BN%5D);%0A            i = (i %3C 0) ? ~i : i+1;%0A            %0A            //OUTPUT%0A            sb.append(i + %22%5Cn%22);%0A        %7D%0A        System.out.print(sb);%0A    %7D%0A    %0A    private static int%5B%5D getPrimes(int N)%7B%0A        final int sqrtN = (int)Math.ceil(Math.sqrt(N));%0A        boolean%5B%5D isComposite = new boolean%5BN%5D;%0A        isComposite%5B0%5D = true;%0A        %0A        int count = 0;%0A        for(int i = 0; i %3C sqrtN; ++i)%7B%0A            if (!isComposite%5Bi%5D)%7B%0A                ++count;%0A                final int prime = i+1;%0A                for(int j = prime*prime - 1; j %3C N; j += prime)%7B%0A                    isComposite%5Bj%5D = true;%0A                %7D%0A            %7D%0A        %7D%0A        %0A        for(int i = sqrtN; i %3C N; ++i)%7B%0A            if (!isComposite%5Bi%5D)%7B%0A                ++count;%0A            %7D%0A        %7D%0A        %0A        int%5B%5D primes = new int%5Bcount%5D;%0A        count = 0;%0A        for(int i = 0; i %3C N; ++i)%7B%0A            if (!isComposite%5Bi%5D)%7B%0A                primes%5Bcount++%5D = i+1;%0A            %7D%0A        %7D%0A        %0A        return primes;%0A    %7D%0A%7D%0A

Create red-john-is-back.java