/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package cf;

import java.util.Stack;

/**
 *
 * @author debmalyajash
 */
public class CodeFighter {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        System.out.println(sumOfThrees("4"));
        System.out.println(sumOfThrees("84"));
        System.out.println(sumOfThrees("531441"));
        System.out.println(sumOfThrees("2"));
        System.out.println(sumOfThrees("5"));

    }

    public static String sumOfThrees(String n) {
        long m = Long.parseLong(n);
        int i = 0;
        StringBuilder sb = new StringBuilder();
        Stack<Integer> s = new Stack<>();

        while (m > 0) {

            long r = m % 3;
            if (r == 2) {
                return "Impossible";
            } else if (r != 0) {
                s.push(i);
            }
            i++;

            m /= 3;
        }

        while (!s.isEmpty()){
            sb.append(3).append("^").append(s.pop()).append("+");
        }
        return sb.toString().substring(0,sb.length()-1);

    }

}

@@ -621,16 +621,134 @@
 s(%225%22));
+%0A        %0A         for (int i = 1; i %3C 14; i++) %7B%0A            System.out.println(i + %22 gamma :%22 + gamma(i));%0A        %7D
 %0A%0A    %7D%0A
@@ -1353,10 +1353,232 @@
 %0A    %7D%0A%0A
+    /**%0A     * This was a reverse challenge.%0A     * @param n - number of term.%0A     * @return value of the nth term.%0A     */%0A    public static int gamma(int n) %7B%0A        return (n == 1) ? 1 : (n - 1) * gamma(n - 1);%0A    %7D%0A
 %7D%0A

Update CodeFighter.java