login
A089754
Smallest prime ending (least significant side) in n if possible else beginning in n.
1
11, 2, 3, 41, 5, 61, 7, 83, 19, 101, 11, 127, 13, 149, 151, 163, 17, 181, 19, 2003, 421, 223, 23, 241, 251, 263, 127, 281, 29, 307, 31, 3203, 233, 347, 353, 367, 37, 383, 139, 401, 41, 421, 43, 443, 457, 461, 47, 487, 149, 503, 151, 521, 53, 541, 557, 563, 157, 587, 59, 601, 61, 6203, 163
OFFSET
1,1
MAPLE
read("transforms)"):
nleadzero := proc(n, dgs)
local ndgs ;
if n = 0 then
ndgs := 0 ;
else
ndgs := ilog10(n)+1 ;
end if;
[op(convert(n, base, 10)), seq(0, i=1..dgs-ndgs)]
end proc:
digcatL2 := proc(L1, L2)
digcatL([op(L1), op(L2)]) ;
end proc:
A089754 := proc(n)
local prep, a, dgs ;
if isprime(n) then
n;
elif modp(n, 2) = 0 or modp(n, 5) = 0 then
ndgs := convert(n, base, 10) ;
for dgs from 1 do
for prep from 0 to 10^dgs-1 do
a := digcatL2(ListTools[Reverse](ndgs), ListTools[Reverse](nleadzero(prep, dgs))) ;
if isprime(a) then
return a;
end if;
end do:
end do:
else
for prep from 1 do
a := digcat2(prep, n) ;
if isprime(a) then
return a;
end if;
end do:
end if;
end proc: # R. J. Mathar, Sep 18 2015
CROSSREFS
KEYWORD
base,easy,nonn
AUTHOR
Amarnath Murthy, Nov 22 2003
EXTENSIONS
Corrected by R. J. Mathar, Sep 18 2015
STATUS
approved