OFFSET
1,1
COMMENTS
If the only preceding square k such that p-k^2 is prime is 0, then we generate sequence A065377.
LINKS
Robert Israel, Table of n, a(n) for n = 1..10000
EXAMPLE
The 7th prime is 17. The preceding squares of 17 are 16,9,4,1,0. The differences are 17-16=1, 17-9=8, 17-4=13, 17-1=16 and 17-0=17. Then 4 is the first preceding square of 17 that can be subtracted from 17 to get a prime. So a(7)=13. If we reduce the prime(6)=13 in this fashion, we have 13-9=4, 13-1=12, 13-0=13. This shows that 0 is the first square that can be subtract from 13 to get a prime number. So a(6)=13.
MAPLE
A157495 := proc(n)
local p, s ;
p := ithprime(n) ;
s := floor(sqrt(p)) ;
while not isprime(p-s^2) do
s := s-1;
end do;
p-s^2 ;
end proc:
seq(A157495(n), n=1..130) ; # R. J. Mathar, Sep 07 2016
MATHEMATICA
Table[SelectFirst[Reverse[p-Range[0, Floor[Sqrt[p]]]^2], PrimeQ], {p, Prime[ Range[80]]}] (* Requires Mathematica version 10 or later *) (* Harvey P. Dale, Oct 23 2017 *)
PROG
(PARI) g(n)= c=0; forprime(x=2, n, for(k=1, n^2, if(issquare(abs(x-k)) && isprime(k), print1(k", "); c++; break))); c
CROSSREFS
KEYWORD
nonn
AUTHOR
Cino Hilliard, Mar 01 2009
EXTENSIONS
NAME rephrased for clarity. - R. J. Mathar, Sep 08 2016
STATUS
approved