A265433 Number of primes with digit sum n whose digit product is maximal among all numbers with digit sum n.
0, 1, 1, 0, 1, 0, 2, 1, 0, 1, 2, 0, 5, 1, 0, 4, 3, 0, 8, 2, 0, 2, 2, 0, 10, 1, 0, 5, 4, 0, 8, 1, 0, 4, 2, 0, 17, 0, 0, 7, 4, 0, 13, 3, 0, 0, 3, 0, 17, 4, 0, 12, 1, 0, 13, 1, 0, 6, 2, 0, 18, 1, 0, 11, 0, 0, 24, 2, 0, 5, 1, 0, 25, 1, 0, 10, 2, 0, 23, 2, 0, 9, 1
Offset: 1
Examples
See examples in A137269. a(4) = 0 since the maximal digit product is 4 corresponding to the numbers 22 and 4, neither of which is prime.
Links
- Chai Wah Wu, Table of n, a(n) for n = 1..2001
Programs
-
Mathematica
f[n_] := Block[{g, a265437 = {1, 4, 38, 46, 65, 94, 107, 116, 128, 131, 140, 143, 149, 152, 170, 188, 227, 230, 248, 272, 293, 302, 317, 335, 344, 359, 371, 382, 404, 488, 530, 533, 551, 584, 626, 647, 722, 767, 803, 815, 866, 875, 893, 914, 920}}, g[k_] := Length@ MaximalBy[k, Times @@ IntegerDigits@ # &]; Which[MemberQ[a265437, n], 0, 1 < n <= 3, 1, Mod[n, 3] == 0, 0, Mod[n, 3] == 1, g@ Select[FromDigits /@ Apply[Join, Map[Permutations, {Join[Table[3, {Floor[n/3] - 1}], {2, 2}], Join[Table[3, {Floor[n/3] - 1}], {4}]}]] /. x_ /; EvenQ@ x -> Nothing, PrimeQ], Mod[n, 3] == 2, g@ Select[FromDigits /@ Permutations@ Join[Table[3, {Floor[n/3]}], {2}] /. x_ /; EvenQ@ x -> Nothing, PrimeQ], True, -1]] (* Michael De Vlieger, Dec 11 2015, Version 10, reliant on values of A265437 *)
-
Python
from _future_ import division from sympy.utilities.iterables import multiset_permutations from sympy import isprime def A265433(n): if n == 1: return 0 if n == 3: return 1 if (n % 3) == 0: return 0 else: pmaxlist = ['3'*(n//3) + '2'] if (n % 3 == 2) else ['3'*(n//3 -1) + '22','3'*(n//3 -1) + '4'] return sum(1 for p in pmaxlist for k in multiset_permutations(p) if isprime(int(''.join(k)))) # Chai Wah Wu, Dec 11 2015
Comments