Smallest integer which cannot be derived from set of numbers Let's assume that I have k number of ns (e.g. 6,6 , k = 2 , n = 6) 
I'd like to find the smallest integer larger than 1 which cannot be derived by any combination of these numbers
Here by combination I mean all the numbers which can be derived by putting 4 main operators (+ , - , / , *) between these numbers.
For example, the numbers which can be created by 2 6's are : 
$6 + 6 = 12$
$6 \cdot 6 = 36$
$6 - 6 = 0 $
$\frac 66 = 1$
Therefore, the smallest such integer would be 2.
I solved this problem in brute force. Is there any better way ? because here the time and space complexity are very high.
public static int smallest_non_combined(int n , int k){
    HashSet<Integer> set = new HashSet<Integer>();
    combination((double)n, k, set, 1 , (double)n);
    double r = 2;
    while (set.contains(r))
        r++;
    return (int)r;
}
public static void combination(double n , int k , HashSet<Integer> set , int index , double r){
    if (index >= k){
        if (r > 1 && r == (int)r)
            set.add((int)r);
    }else{
        combination(n , k , set , index+1, r + n);
        combination(n , k , set , index+1, r * n);
        combination(n , k , set , index+1, r / n);
        combination(n , k , set , index+1, r - n);
    }
    return;
}


If you use Reverse Polish Notation, you can get rid of the parenthesis all together. Then generating the combinations is fairly trivial:
for three 5s we have two possibilities, + denotes an operation which can be +, -, / or *:
5 5 5 + +      √
5 5 + 5 +      √
5 + + 5 5      X
+ 5 5 5 +      X
...

One observation is that the expression always starts with two numbers from left and always ends with an operators. You can start from left and two numbers and either add a number or an operator. At each step number of operators should not equal number of operands. For instance, if you get to the point that you have:
5 5 5 + + +

You can discard and generate next combination. But even with this approach calculating for 10 2s is quite time consuming.
