OFFSET
1,1
EXAMPLE
a(4) = 894500063 because A367798(3) = 35419 and 35419^2 = 1254505561 = 894500063 + 360005498 and 894500063 is the greatest prime that works.
MAPLE
f:= proc(n) local y, c, d, dp, i, delta, m;
y:= convert(n^2, base, 10);
d:= nops(y);
if d::even then
if y[-1] <> 1 then return false fi;
dp:= d-1;
y:= y[1..-2];
c[dp]:= 1;
else
dp:= d;
c[dp]:= 0;
fi;
c[0]:= 0;
for i from 1 to floor(dp/2) do
delta:= y[i] - y[dp+1-i] - c[i-1] - 10*c[dp+1-i];
if delta = 0 then c[dp-i]:= 0; c[i]:= 0;
elif delta = -1 then c[dp-i]:= 1; c[i]:= 0;
elif delta = -10 then c[dp-i]:= 0 ; c[i]:= 1;
elif delta = -11 then c[dp-i]:= 1; c[i]:= 1;
else return false
fi;
if y[i] + 10*c[i] - c[i-1] < 0 or (i=1 and y[i]+10*c[i]-c[i-1]=1) then return false fi;
od;
m:= (dp+1)/2;
delta:= y[m] + 10*c[m] - c[m-1];
if not member(delta, [seq(i, i=0..18, 2)]) then return false fi;
[seq(y[i]+ 10*c[i]-c[i-1], i=1..m)]
end proc:
g:= proc(L) local T, d, t, p, x, i; uses combinat;
d:= nops(L);
T:= cartprod([select(t -> t[1]::odd, [seq([L[1]-x, x], x=min(L[1], 9)..max(1, L[1]-9), -1)]),
seq([seq([L[i]-x, x], x=min(9, L[i])..max(0, L[i]-9), -1)], i=2..d-1)]);
while not T[finished] do
t:= T[nextvalue]();
p:= add(t[i][1]*10^(i-1), i=1..d-1) + L[-1]/2 * 10^(d-1) +
add(t[i][2]*10^(2*d-i-1), i=1..d-1);
if isprime(p) then return p fi;
od;
-1
end proc:
p:= 2, 11: Q:= 83:
while p < 10^10 do
p:= nextprime(p);
d:= 1+ilog10(p^2);
if d::even and p^2 >= 2*10^(d-1) then p:= nextprime(floor(10^(d/2))); fi;
v:= f(p);
if v = false then next fi;
q:= g(v);
if q = -1 then next fi;
Q:= Q, q;
od:
Q;
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Robert Israel, Dec 04 2023
STATUS
approved