Generate all possible integers Input: you are given 2 integers, n and k. n is a positive (>= 1) integer, and k an integer, which is the number of times you are allowed to use n. 

Output: output all of the non-negative integers that can be formed using at most k n's using these mathematical operations: +, -, *, /, and parentheses. 

Edit: if your language supports removing elements from an array/set/etc., the requirement of non-negative integers is required. If not, then it is not required.

The only numerical value that can exist in the expression is n (however many times). If the value of the expression exceeds the maximum value of whatever data storage you have (such as int or long, etc.), you have to compensate for it (there is no maximum value that can be given for n).

Speed is not important, but shortest code wins!

Bonuses:


-50: include exponentiation in the list of mathematical operations. Exponentiation is defined to be that the base is some expression of n, not e = 2.71828...
-50: include the floor (or ceiling) functions if a given possible operation is not an integer.


Examples

&gt; 2 2
0 1 4
&gt; 4 3
3 4 5 12 20 64 ...


(Sample inputs/outputs do not necessarily include bonuses)
Javascript (E6) 215 (315 - 2*50 bonus) 252

Edit Simplified. Correct bug of 0 missing

Defined as a function, then counting 10 more byte for output using alert()

Important Really this one is not valid according to the rules, because javascript can not handle big numbers. For instance with parameters 2,5 it can't find 2^2^2^2^2 (ie 2^65536). A number this big is 'Infinity' in javascript.

Golfed

F=(n,k,g={})=&gt;{k+=k-1;for (l=i=1;x=i.toString(6),l+=!!x[l],l&lt;k;i++)if(x.split(0).length*2==l+1){for(s=[n,n],p=l;o=x[--p];)
if(-o)b=s.pop(),a=s.pop(),s.push(o&lt;2?a+b:o&lt;3?a-b:o&lt;4?a*b:o&lt;5?a/b:Math.pow(a,b));else s.push(x[p]=n);
r=Math.floor(s.pop());r&gt;=0&amp;isFinite(r)&amp;!isNaN(r)&amp;!g[r]&amp;&amp;(g[r]=x)}return Object.keys(g)};


To be golfed. I have an idea I want to share: use a postfix notation. In postfix any type of expression is made just of values and operators - no parentheses needed.
The postfix notation can be translated to usual algebraic infix notation - but that's out of scope in this challenge.

Usage

alert(F(4,3))


Output 1,2,3,4,5,8,12,16,20,32,64,252,256,260,1024,4096,65536,4294967296,1.3407807929942597e+154

Ungolfed

F=(n, k, g={})=&gt;{
  k += k - 1;
  // Count in base 6 - '0' means Value, '1'..'5' means operators
  // A valid expression starts with Value twice, then n operators intermixed with n-1 Values
  // x: Coded expression, l: Expression length, k Expression limit length from param
  for (l = i = 1; x = i.toString(6), l += !!x[l], l&lt;k; i++)
    if (x.split(0).length*2 == l+1) // check balancing values/operators
    {
      for (s = [n,n], p = l; o = x[--p];) // Calc stack starts with N,N
        if (-o) // If not '0'
          b=s.pop(),a=s.pop(), // Do calc
          s.push(o&lt;2 ? a+b : o&lt;3 ? a-b : o&lt;4 ? a*b : o&lt;5 ? a/b : Math.pow(a,b))
        else // Push value 
          s.push(n) // 
      r = Math.floor(s.pop()); // Last result in stack
      r &gt;= 0 &amp; isFinite(r) &amp; !isNaN(r) &amp; !g[r] &amp;&amp; (g[r]=x) // Put in hashtable avoiding duplicates
    }
  // Uncomment this to see the postfix expression list 
  // for (i in g) console.log(i, [n,n,...[...g[i]].reverse().map(v=&gt;v&gt;0?'x+-*/^'[v]:n)])
  return Object.keys(g) // Retust list of hashtable keys
}


First version this is more complicated but maybe easier to follow

Display the postfix expression for each number

F=(n,k)=&gt; {
  var i,l,s;
  var cmd;
  var op='n+-*/^'
  var bag = {}
  function Calc(val,pos,stack)
  {
    while (c = cmd[pos])
    {
        if (c == 0)
        {
            stack.push(n);
            cmd[pos] = n
            pos++
        }
        else 
        {
            var b=stack.pop(), a=stack.pop();
            stack.push(c &lt; 2 ? a+b : c &lt; 3 ? a-b : c &lt; 4 ? a*b : c &lt; 5 ? a/b
               : Math.pow(a,b))
            cmd[pos]=op[c]
            pos++
        }
    }
    var res = Math.floor(stack.pop())
    if (res &gt; 0 &amp;&amp; isFinite(res) &amp;&amp; !isNaN(res) &amp;&amp; !bag[res]) 
    {
       bag[res] = cmd
    }
  }
  k=k+k-3;
  for (i=1;s=i.toString(6), !s[k]; i++)
  {
       l=s.split(0).length;
       if (l+l-1==s.length) 
       {
          var cmd = (s+'00').split('').reverse()
          Calc(n, 0, [], cmd.map(c=&gt;op[c]).join(' '))
       }
  }

  for (i in  bag)
  {
    console.log(bag[i],'=', i)
  }
}


Usage

F(4,3)


Output

[4, 4, "/"] = 1
[4, 4, "+", 4, "/"] = 2
[4, 4, 4, "/", "-"] = 3
[4, 4, "-", 4, "+"] = 4
[4, 4, "/", 4, "+"] = 5
[4, 4, "+"] = 8
[4, 4, "+", 4, "+"] = 12
[4, 4, "*"] = 16
[4, 4, "*", 4, "+"] = 20
[4, 4, "+", 4, "*"] = 32
[4, 4, "*", 4, "*"] = 64
[4, 4, "^", 4, "-"] = 252
[4, 4, "^"] = 256
[4, 4, "^", 4, "+"] = 260
[4, 4, "^", 4, "*"] = 1024
[4, 4, "+", 4, "^"] = 4096
[4, 4, "*", 4, "^"] = 65536
[4, 4, "^", 4, "^"] = 4294967296
[4, 4, 4, "^", "^"] = 1.3407807929942597e+154