OFFSET
1,1
COMMENTS
a(n) is prime for all n<=10^10 except a(13)=21.
a(n) <= 2n + 1.
a(n) = 2n + 1 if and only if 2n + 1 is prime.
a(n) = 2n - 1 if and only if 2n - 1 is a prime and 2n - 1 = 1 mod 6.
a(n) = 2n - 3 if and only if 2n - 3 is a prime and 2n - 3 = 1 mod 30.
LINKS
Moritz Firsching, Table of n, a(n) for n = 1..9999
PROG
(Sage)
def a(n):
g=n
n+=1
while(g!=0):
g=g-gcd(n, g)
n+=1
return n
(PARI)
a(last_a) = {
local(A=last_a, B=last_a, C=2*last_a+1);
while(A>0,
D=divisors(C);
k1=10*D[2];
for(j=2, matsize(D)[2], d=D[j]; k=((A+1-B+d)/2)%d;
if(k==0, k=d); if(k<=k1, k1=k; d1=d));
if(k1-1+d1==A, B=B+1);
A = max(A-(k1-1)-d1, 0);
B = B + k1;
C = C - (d1 - 1);
);
return(B);
}
a(n)={
my(A=n, B=n, C=2*n+1);
while(A>0,
my(k1=oo, d1);
fordiv(C, d,
if(d==1, next);
my(k=((A+1-B+d)/2)%d);
if(k==0, k=d);
if(k<=k1, k1=k; d1=d)
);
A -= k1 - 1 + d1;
B += k1 + (A==0);
C -= d1 - 1;
);
B;
} \\ Charles R Greathouse IV, Nov 04 2015
CROSSREFS
KEYWORD
nonn
AUTHOR
Moritz Firsching, Aug 04 2015
STATUS
approved