@@ -0,0 +1,1154 @@
+import java.util.ArrayList;%0Aimport java.util.HashSet;%0Aimport java.util.List;%0Aimport java.util.Set;%0A%0Apublic class PowerfulIntegers %7B%0A%0A    public static void main(String%5B%5D args) %7B%0A        System.out.println(new PowerfulIntegers().powerfulIntegers(2, 3, 10));%0A        System.out.println(new PowerfulIntegers().powerfulIntegers(3, 5, 15));%0A        System.out.println(new PowerfulIntegers().powerfulIntegers(2, 1, 10));%0A        System.out.println(new PowerfulIntegers().powerfulIntegers(1, 2, 100));%0A    %7D%0A%0A    public List%3CInteger%3E powerfulIntegers(int x, int y, int bound) %7B%0A        Set%3CInteger%3E results = new HashSet%3C%3E();%0A        int maxExponentX = x %3E 1 ? (int) (Math.log(bound) / Math.log(x)) : 1;%0A        int maxExponentY = y %3E 1 ? (int) (Math.log(bound) / Math.log(y)) : 1;%0A        for (int i = 0; i %3C= maxExponentX; i++) %7B%0A            int powX = (int) Math.pow(x, i);%0A            for (int j = 0; j %3C= maxExponentY; j++) %7B%0A                int powY = (int) Math.pow(y, j);%0A                if (powX + powY %3C= bound) %7B%0A                    results.add(powX + powY);%0A                %7D%0A            %7D%0A        %7D%0A        return new ArrayList%3C%3E(results);%0A    %7D%0A%7D%0A

Add PowerfulIntegers