login

Reminder: The OEIS is hiring a new managing editor, and the application deadline is January 26.

Number of nonnegative integers that can be computed using exactly n n's and the four basic arithmetic operations {+, -, *, /}.
11

%I #17 Aug 29 2021 12:01:41

%S 1,3,9,26,68,198,536,1660,4769,15945,46240,165732,488268,1848866,

%T 5852344

%N Number of nonnegative integers that can be computed using exactly n n's and the four basic arithmetic operations {+, -, *, /}.

%p a:= proc(n) option remember; local f; f:=

%p proc(m) option remember; `if`(m=1, {n}, {

%p seq(seq(seq([x+y, x-y, x*y, `if`(y=0, [][], x/y)

%p ][], y=f(m-j)), x=f(j)), j=1..m-1)})

%p end; forget(f);

%p nops([select(z->z>=0 and is(z, integer), f(n))[]])

%p end:

%p seq(a(n), n=1..9);

%t a[n_] := a[n] = Module[{f}, f[m_] := f[m] = If[m == 1, {n},

%t Union@ Flatten@ Table[Table[Table[{x + y, x - y, x*y,

%t If[y == 0, Nothing, x/y]}, {y, f[m-j]}], {x, f[j]}], {j, m-1}]];

%t Length[Select[f[n], # >= 0 && IntegerQ[#]&]]];

%t Table[a[n], {n, 1, 9}] (* _Jean-François Alcover_, Aug 29 2021, after _Alois P. Heinz_ *)

%o (Python)

%o from fractions import Fraction

%o from functools import lru_cache

%o def a(n):

%o @lru_cache()

%o def f(m):

%o if m == 1: return {Fraction(n, 1)}

%o out = set()

%o for j in range(1, m):

%o for x in f(j):

%o for y in f(m-j):

%o out.update([x + y, x - y, x * y])

%o if y: out.add(Fraction(x, y))

%o return list(out)

%o return sum(num >= 0 and num.denominator == 1 for num in f(n))

%o print([a(n) for n in range(1, 10)]) # _Michael S. Branicky_, Aug 29 2021 after _Alois P. Heinz_

%Y Cf. A171826, A171827, A171828, A171829, A258068, A258069, A258070, A258071.

%K nonn,more

%O 1,2

%A _Alois P. Heinz_, May 19 2015

%E a(13)-a(14) from _Giovanni Resta_, May 20 2015

%E a(15) from _Michael S. Branicky_, Aug 29 2021