login
Number of different positive integers that we can obtain from the integers {1,2,...,n} using each number at most once and the operators +, -, *, /, where intermediate subexpressions must be integers.
0

%I #12 Jul 01 2022 22:05:44

%S 1,3,9,31,121,542,2868,16329,106762,758155,6142570

%N Number of different positive integers that we can obtain from the integers {1,2,...,n} using each number at most once and the operators +, -, *, /, where intermediate subexpressions must be integers.

%H <a href="/index/Fo#4x4">Index entries for similar sequences</a>

%e a(4)=31 because we can obtain the positive integers 1,2,...,28 and 30,32,36 by using the integers {1, 2, 3, 4} at most once and the four operations. For example 30 = 3*2*(4+1).

%o (Python)

%o def a(n):

%o R = dict() # index of each reachable subset is [card(s)-1][s]

%o for i in range(n): R[i] = dict()

%o for i in range(1, n+1): R[0][(i,)] = {i}

%o reach = set(range(1, n+1))

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

%o for i in range((j+1)//2):

%o for s1 in R[i]:

%o for s2 in R[j-1-i]:

%o if set(s1) & set(s2) == set():

%o s12 = tuple(sorted(set(s1) | set(s2)))

%o if s12 not in R[len(s12)-1]:

%o R[len(s12)-1][s12] = set()

%o for a in R[i][s1]:

%o for b in R[j-1-i][s2]:

%o allowed = [a+b, a*b, a-b, b-a]

%o if a!=0 and b%a==0: allowed.append(b//a)

%o if b!=0 and a%b==0: allowed.append(a//b)

%o R[len(s12)-1][s12].update(allowed)

%o reach.update(allowed)

%o return len(set(r for r in reach if r > 0 and r.denominator == 1))

%o print([a(n) for n in range(1, 9)]) # _Michael S. Branicky_, Jul 01 2022

%Y Cf. A060315, A070960, A071848.

%K more,nonn

%O 1,2

%A Koksal Karakus (karakusk(AT)hotmail.com), Jun 02 2002

%E a(10)-a(11) from _Michael S. Branicky_, Jul 01 2022