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],