login
Semiprimes which when truncated arbitrarily on either side in base 10 yield semiprimes.
1

%I #27 Aug 23 2018 20:59:19

%S 4,6,9,46,49,69,94,469,694,949,4694

%N Semiprimes which when truncated arbitrarily on either side in base 10 yield semiprimes.

%C There are exactly 3 1-digit terms, 4 2-digit terms, 3 3-digit terms, and 1 4-digit term.

%C After the 4-digit term, there are no more terms in this sequence. This is provable by induction: There are no 5-digit terms. If there are no k-digit terms, there are no (k+1)-digit terms. (If there were, then said term, when truncated on either side, would produce a k-digit number that is in the sequence.) Therefore, there are no terms that have at least 5 digits.

%C The sequence 3, 4, 3, 1, 0, 0, ... does not appear to be significant.

%C This sequence depends on base 10 and is nonnegative.

%C Any truncation of a number in this sequence yields another number in this sequence. If one did not, then truncating the number more would yield a non-semiprime, which is impossible.

%C Base 10 is the first base in which this sequence contains 3-digit terms.

%H Keith J. Bauer, <a href="http://tpcg.io/cSo9J1">"A317248 (Python v2.7.13)"</a>

%e 4694 is a semiprime (2 * 2347), and its truncations are, too: 469 (7 * 67), 694 (2 * 347), 46 (2 * 23), etc.

%t ok[w_, n_] := AllTrue[Flatten@ Table[ FromDigits@ Take[w, {i, j}], {i, n}, {j, i, n}], PrimeOmega[#] == 2 &]; Union @@ Reap[ Do[Sow[ FromDigits /@ Select[Tuples[{4, 6, 9}, n], ok[#, n] &]], {n, 5}]][[2, 1]] (* _Giovanni Resta_, Jul 26 2018 *)

%o (Python) #v2.7.13, see LINKS to run it online.

%o #semitest(number, 0) returns True iff number is a semiprime

%o def semitest(number, factors):

%o if number != 2:

%o for p in [2] + range(3, int(number ** 0.5) + 1, 2):

%o if number % p == 0:

%o if factors < 2:

%o return semitest(number / p, factors + 1)

%o else:

%o return False

%o if factors == 1:

%o return True

%o else:

%o return False

%o #main function

%o def doIt(base):

%o #initialization

%o numbers = [[]]

%o indices_list = [[]]

%o i = 0

%o for number in range(1, base):

%o if semitest(number, 0):

%o numbers[0].append(number)

%o indices_list[0].append([i])

%o i += 1

%o #numbers[0] is the digit pool

%o #numbers[-1] is to be appended to

%o #numbers[-2] is for reference to past numbers

%o #indices_list records the indices of numbers

%o numbers.append([])

%o indices_list.append([])

%o #main while loop, go until there are no numbers left in the sequence

%o indices = [0, 0]

%o while len(numbers[-2]) > 0:

%o #test number

%o if indices[:-1] in indices_list[-2]:

%o if indices[1:] in indices_list[-2]:

%o #little-endian

%o number = 0

%o power = 0

%o for index in indices:

%o number += numbers[0][index] * base ** power

%o power += 1

%o if semitest(number, 0):

%o numbers[-1].append(number)

%o indices_list[-1].append(indices[:])

%o #increment indices

%o for i in range(len(indices)):

%o indices[i] += 1

%o if indices[i] == len(numbers[0]):

%o indices[i] = 0

%o if i == len(indices) - 1:

%o indices = [0] * len(indices) + [0]

%o numbers.append([])

%o indices_list.append([])

%o else:

%o break

%o #print results after while loop has run

%o print base, sum(numbers, [])

%o print numbers

%o #call main function

%o doIt(10)

%o (Python)

%o from sympy import factorint

%o A317248_list = xlist = [4,6,9]

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

%o ylist = []

%o for i in (4,6,9):

%o for x in xlist:

%o if sum(factorint(10*x+i).values()) == 2 and (10*x+i) % 10**n in xlist:

%o ylist.append(10*x+i)

%o elif sum(factorint(x+i*10**n).values()) == 2 and (x//10+i*10**(n-1)) in xlist:

%o ylist.append(x+i*10**n)

%o xlist = set(ylist)

%o if not len(xlist):

%o break

%o A317248_list.extend(xlist)

%o A317248_list.sort() # _Chai Wah Wu_, Aug 23 2018

%Y Cf. A001358.

%Y Subset of A107342 and A086698.

%K base,fini,full,nonn

%O 1,1

%A _Keith J. Bauer_, Jul 24 2018