OFFSET
1,3
COMMENTS
a(n) = prime(k) for the least k such that A121889(k) = n, or -1 if there is no such k.
EXAMPLE
a(5) = 7 because 7 is prime, the next prime is 11, (7 mod 5) = 2 > (11 mod 5) = 1, while (7 mod k) <= (11 mod k) for k = 1, 2, 3 and 4.
a(6) = -1 because there are no such p. The only possibility for (p,q) mod 6 where p and q are primes > 6 and (p mod 6) > (q mod 6) is (5,1), but in that case (p mod 3) = 2 > (q mod 3) = 1.
MAPLE
V:= Vector(39):
check:= proc(m) local P, nP, Cands, i, j, D;
P:= select(t -> igcd(t, m) = 1, [$1 .. m-1]); nP:= nops(P);
Cands:= [seq(seq([P[i], P[j]], i=1..j-1), j=2..nP)];
D:= NumberTheory:-Divisors(m) minus {1, m};
ormap(c -> andmap(d -> (c[1] mod d) >= (c[2] mod d), D), Cands)
end proc:
g:= proc(a, b) local m;
for m from 2 do if (a mod m) > (b mod m) then return m fi od
end proc:
V[remove(check, [$1..39])] := -1:
q:= 2:
for x from 1 while has(V, 0) do
p:= q; q:= nextprime(q);
v:= g(p, q);
if v <= 39 and V[v] = 0 then V[v]:= p fi;
od:
convert(V, list);
CROSSREFS
KEYWORD
sign,new
AUTHOR
Robert Israel, May 20 2026
STATUS
approved
