OFFSET
1,1
COMMENTS
LINKS
Jianing Song, Table of n, a(n) for n = 1..350
Jianing Song, Table of n, a(n)/(4*p_2*...*p_n) for n = 3..10000.
Jianing Song, Terms of A396867.
FORMULA
Let p_i = prime(i), q_i = A002144(i) be the i-th prime congruent to 1 modulo 4, and r_i = A002145(i) be the i-th prime congruent to 3 modulo 4. Suppose that {p_2, ..., p_n} = {q_1, ..., q_{n-1-m}} U {r_1, ..., r_m}. Write N = 4*p_2*...*p_n. For n >= 3:
- If m is even, then a(n) = N.
- If m is odd, then a(n) is either (q_{n-m}/r_m)*N or (r_{m+1}/q_{n-1-m})*N (i.e., obtained by either removing the largest prime <= prime(n) congruent to 1 modulo 4 and adding the least prime > prime(n) congruent to 3 modulo 4, or removing the largest prime <= prime(n) congruent to 3 modulo 4 and adding the least prime > prime(n) congruent to 1 modulo 4).
See my link "Terms of A396867" above.
EXAMPLE
For n = 3, we have {3, 5} = {q_1=5} U {r_1=3}. Since the number of primes congruent to 3 modulo 4 is odd, a(n) is the minimum between 4*5*13 and 4*3*7, which is 4*3*7 = 84.
For n = 7, we have {3, 5, 7, 11, 13, 17} = {q_1=5, q_2=13, q_3=17} U {r_1=3, r_2=7, r_3=11}. Since the number of primes congruent to 3 modulo 4 is odd, a(n) is the minimum between 4*5*13*17*29*3*7 and 4*5*13*3*7*11*19, which is 4*5*13*3*7*11*19 = 1141140.
PROG
(PARI) a(n) = {
if(n==1, return(3));
if(n==2, return(15));
my(N=4, res=1, plim=prime(n), q, r);
forprime(p=3, plim, N=N*p; res=(res*p)%4; if(p%4==1, q=p, r=p)); \\ N = 4*p_2*...*p_n, q is the largest prime <= p_n congruent to 1 mod 4, r is the largest prime <= p_n congruent to 3 mod 4
if(res==1, return(N)); \\ if the number of primes <= p_n congruent to 3 mod 4 is even, then a(n) = N
forprime(p=plim+1, oo, if(p%4==3, q=p/q; break())); \\ smallest prime > p_n congruent to 3 mod 4
forprime(p=plim+1, oo, if(p%4==1, r=p/r; break())); \\ smallest prime > p_n congruent to 1 mod 4
return(N * min(q, r));
}
CROSSREFS
KEYWORD
nonn,new
AUTHOR
Jianing Song, Jun 08 2026
STATUS
approved
