login
A101991
Largest prime which can be formed from digits of n, or 0 if no such prime exists.
2
0, 2, 3, 0, 5, 0, 7, 0, 0, 0, 11, 2, 31, 41, 5, 61, 71, 0, 19, 2, 2, 2, 23, 2, 5, 2, 7, 2, 29, 3, 31, 23, 3, 43, 53, 3, 73, 83, 3, 0, 41, 2, 43, 0, 5, 0, 47, 0, 0, 5, 5, 5, 53, 5, 5, 5, 7, 5, 59, 0, 61, 2, 3, 0, 5, 0, 67, 0, 0, 7, 71, 7, 73, 47, 7, 67, 7, 7, 97, 0, 0, 2, 83, 0, 5, 0, 7, 0, 89, 0, 19
OFFSET
1,2
LINKS
EXAMPLE
a(115)=151 because 151 is the largest prime which can be made from digits {1,1,5}.
MAPLE
f:= proc(n) local L, N, d, i, j, S, s, p;
L:= convert(n, base, 10);
N:= nops(L);
for d from N to 1 by -1 do
S:= sort(combinat:-permute(L, d));
for i from nops(S) to 1 by -1 do
s:= S[i];
p:= add(s[j]*10^(d-j), j=1..d);
if isprime(p) then return p fi
od od;
0
end proc:
map(f, [$1..100]); # Robert Israel, Jan 10 2024
MATHEMATICA
a[n_]:=Max[0, Select[FromDigits/@Permutations[IntegerDigits[n], {1, IntegerLength[n]}], PrimeQ]]; Table[a[n], {n, 91}] (* James C. McMahon, Jan 08 2024 *)
CROSSREFS
Sequence in context: A331097 A047814 A365276 * A296065 A174900 A344369
KEYWORD
base,easy,nonn,look
AUTHOR
Zak Seidov, Jan 29 2005
STATUS
approved