|
MAPLE
|
# Returned values of -1 indicate that either a(n) = 0 or a(n) > 10^1000.
f:= proc(n) local m, x, y, S, cf, i, c, a, b, A, M, Sp;
m:= n+1;
if issqr(m) then
S:= [isolve(x^2+n=m*y^2)];
S:= map(t -> subs(t, [x, y]), S);
S:= select(t -> andmap(isprime, t), S);
if S = [] then return 0
else return min(map(t -> t[2], S))
fi;
fi;
cf:= NumberTheory:-ContinuedFraction(sqrt(m));
for i from 1 do
c:= Convergent(cf, i);
if numer(c)^2 - m*denom(c)^2 = 1 then break fi
od;
a:= numer(c); b:= denom(c);
A:= <<a, b>|<m*b, a>>;
M:= floor(sqrt(n)*(1+sqrt(a+b*sqrt(m)))/(2*sqrt(m)));
S:= select(t -> issqr(m*t^2-m+1), [$0..M]);
S:= select(t -> igcd(t[1], t[2])=1, map(t -> <sqrt(m*t^2-m+1), t>, S));
S:= map(t -> (t, <-t[1], t[2]>), S);
if nops(S) = 0 then return 0 fi;
for i from 0 do
Sp:= select(t -> isprime(t[1]) and isprime(t[2]), S);
if nops(Sp)>0 then return min(map(t -> t[2], Sp)) fi;
S:= map(t -> A.t, S);
if min(map(t -> t[2], S))>10^1000 then break fi;
od;
-1
end proc:
map(f, [$1..20]);
|