login

Reminder: The OEIS is hiring a new managing editor, and the application deadline is January 26.

Largest prime which can be formed from digits of n, or 0 if no such prime exists.
2

%I #18 Jan 12 2024 22:46:13

%S 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,

%T 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,

%U 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

%N Largest prime which can be formed from digits of n, or 0 if no such prime exists.

%H Robert Israel, <a href="/A101991/b101991.txt">Table of n, a(n) for n = 1..10000</a>

%e a(115)=151 because 151 is the largest prime which can be made from digits {1,1,5}.

%p f:= proc(n) local L,N,d,i,j,S,s,p;

%p L:= convert(n,base,10);

%p N:= nops(L);

%p for d from N to 1 by -1 do

%p S:= sort(combinat:-permute(L,d));

%p for i from nops(S) to 1 by -1 do

%p s:= S[i];

%p p:= add(s[j]*10^(d-j),j=1..d);

%p if isprime(p) then return p fi

%p od od;

%p 0

%p end proc:

%p map(f, [$1..100]); # _Robert Israel_, Jan 10 2024

%t a[n_]:=Max[0, Select[FromDigits/@Permutations[IntegerDigits[n], {1, IntegerLength[n]}], PrimeQ]]; Table[a[n], {n, 91}] (* _James C. McMahon_, Jan 08 2024 *)

%K base,easy,nonn,look

%O 1,2

%A _Zak Seidov_, Jan 29 2005