A371024 a(n) is the least prime p such that p + 4*k*(k+1) is prime for 0 <= k <= n-1 but not for k=n.
2, 3, 29, 5, 23, 269, 272879, 149, 61463, 929, 7426253, 2609, 233, 59, 78977932125503
Offset: 1
Programs
-
Maple
f:= proc(p) local k; for k from 1 while isprime(p+k*(k+1)*4) do od: k end proc: A:= Vector(12): count:= 0: for i from 1 while count < 12 do v:= f(ithprime(i)); if A[v] = 0 then count:= count+1; A[v]:= ithprime(i) fi od: convert(A,list);
-
Mathematica
Table[p=1;m=4;Monitor[Parallelize[While[True,If[And[MemberQ[PrimeQ[Table[p+m*k*(k+1),{k,0,n-1}]],False]==False,PrimeQ[p+m*n*(n+1)]==False],Break[]];p++];p],p],{n,1,10}]
-
PARI
isok(p, n) = for (k=0, n-1, if (! isprime(p + 4*k*(k+1)), return(0))); return (!isprime(p + 4*n*(n+1))); a(n) = my(p=2); while (!isok(p, n), p=nextprime(p+1)); p; \\ Michel Marcus, Mar 12 2024
-
Perl
use ntheory qw(:all); sub a { my $n = $[0]; my $lo = 2; my $hi = 2*$lo; while (1) { my @terms = grep { !is_prime($ + 4*$n*($n+1)) } sieve_prime_cluster($lo, $hi, map { 4*$*($+1) } 1 .. $n-1); return $terms[0] if @terms; $lo = $hi+1; $hi = 2*$lo; } }; $| = 1; for my $n (1..100) { print a($n), ", " }; # Daniel Suteu, Dec 17 2024
-
Python
from sympy import isprime, nextprime from itertools import count, islice def f(p): k = 1 while isprime(p+4*k*(k+1)): k += 1 return k def agen(verbose=False): # generator of terms adict, n, p = dict(), 1, 1 while True: p = nextprime(p) v = f(p) if v not in adict: adict[v] = p if verbose: print("FOUND", v, p) while n in adict: yield adict[n]; n += 1 print(list(islice(agen(), 14))) # Michael S. Branicky, Apr 12 2024
Extensions
a(15) from Daniel Suteu, Dec 17 2024
Comments