OFFSET
2,1
COMMENTS
Suggested by Legendre's conjecture (still open) that for n > 0 there is always a prime between n^2 and (n+1)^2 and mentioned to the author by Jack Laffan.
LINKS
Vaclav Kotesovec, Table of n, a(n) for n = 2..10000
Eric Weisstein's World of Mathematics, Legendre's Conjecture
Wikipedia, Legendre's conjecture
EXAMPLE
a(3) = 3 since the longest sequence of consecutive primes in [9, 10, 11, 12, 13, 14, 15, 16] is the length three sequence 14, 15, 16.
MAPLE
RunsOfOnes:=proc(L)
local j, r, i, k;
j:=1:
r[j]:=L[1]:
for i from 2 to nops(L) do
if L[i]=L[i-1] then r[j]:=r[j], L[i]; else
j:=j+1;
r[j]:=L[i];
fi;
od;
j;
[seq([r[k]], k=1..j)];
select(has, %, 1);
end proc:
f:=proc(n)
if isprime(n) then return 0; else return 1; fi;
end proc:
a:=proc(n)
local i;
[seq(i, i=n^2..(n+1)^2)];
map(f, %);
RunsOfOnes(%);
map(nops, %);
max(op(%));
end proc:
seq(a(n), n=2..100);
# second Maple program:
a:= proc(n) local i, maxsofar, scanmax;
maxsofar, scanmax:= 0, 0;
for i from n^2 to (n+1)^2 do
if isprime(i)
then scanmax:= 0
else scanmax:= scanmax+1;
maxsofar:= max(scanmax, maxsofar)
fi
od; maxsofar
end:
seq(a(n), n=2..100); # Alois P. Heinz, Apr 20 2017
MATHEMATICA
Table[s=0; smax=0; Do[If[PrimeQ[j], If[s>smax, smax=s]; s=0, s++], {j, n^2, (n+1)^2}]; If[s>smax, smax=s]; smax, {n, 2, 100}] (* Vaclav Kotesovec, Apr 20 2017 *)
max[n_]:=Max[Length/@Split[Select[Range[n^2, (n+1)^2], CompositeQ], #2-#1==1&]];
max/@Range[2, 100] (* Ivan N. Ianakiev, Apr 21 2017 *)
CROSSREFS
KEYWORD
nonn
AUTHOR
W. Edwin Clark, Apr 12 2017
STATUS
approved