OFFSET
1,1
COMMENTS
If n is odd, a(n) is either n+2 (if n+2 is prime) or 0; if n is even, a(n) is the least prime p such that p-n is prime. Polignac's conjecture implies that such a prime exists. - Robert Israel, Sep 29 2014
FORMULA
a(n) = n+Min{x prime; n+x is prime} or a(n)=0 if Min{} does not exist.
EXAMPLE
a(n)=0, i.e., no solution exists if n is a special prime, namely n is not a lesser twin prime; e.g., if n=7, then neither 7+2=9 nor 7+(oddprime) is a prime, thus no p prime exists such that 7+p is also a prime.
If n is a lesser twin prime then a(n)=2 is a solution because n+a(n) = n+2 = greater twin prime satisfying the condition.
MAPLE
N:= 1000: # to get the first N terms
nToDo:= floor(N/2): OddPrimes[1]:= 3: A[1]:= 3:
for i from 1 to floor(N/2) do A[2*i+1]:= 0 od:
for j from 2 while nToDo > 0 do
OddPrimes[j]:= nextprime(OddPrimes[j-1]);
A[OddPrimes[j]-2]:= OddPrimes[j];
for i from 1 to j-1 do
d:= OddPrimes[j] - OddPrimes[i];
if d <= N and not assigned(A[d]) then
A[d]:= OddPrimes[j];
nToDo:= nToDo-1;
fi
od
od:
seq(A[j], j=1..N); # Robert Israel, Sep 29 2014
PROG
(PARI) a(n) = {if (n % 2, if (isprime(n+2), p = 2, p = 0); , p = 2; while (!isprime(n+p), p = nextprime(p+1)); ); if (p, n + p, 0); } \\ Michel Marcus, Dec 26 2013
CROSSREFS
KEYWORD
nonn
AUTHOR
Labos Elemer, Sep 04 2003
EXTENSIONS
Some corrections by Michel Marcus, Dec 26 2013
STATUS
approved