%I #17 Oct 28 2023 14:40:57
%S 2,3,29,28025,2467754261
%N a(n) = smallest k such that A366475(k) >= n, or -1 if no such k exists.
%t nn = 2^16; c[_] := False; m[_] := 0; j = 1; c[0] = c[1] = True; q[_] := 0; s = -1;
%t Monitor[Do[p = Prime[n - 1]; r = Mod[j, p];
%t While[Set[k, p m[p] + r ]; c[k], m[p]++];
%t (If[q[#] == 0, Set[q[#], n]]; If[# > s, s = #]) &[ m[p] ];
%t Set[{c[k], j}, {True, k}], {n, 2, nn}], n];
%t Array[q, s] (* _Michael De Vlieger_, Oct 27 2023 *)
%o (Python)
%o from itertools import count
%o from sympy import nextprime
%o def A366477(n):
%o a, aset, p = 1, {0,1}, 1
%o for i in count(2):
%o p = nextprime(p)
%o b = a%p
%o for j in count(0):
%o if b not in aset:
%o aset.add(b)
%o a = b
%o break
%o b += p
%o if j>=n:
%o return i # _Chai Wah Wu_, Oct 27 2023
%Y Cf. A364054, A366475.
%K nonn,more
%O 1,1
%A _N. J. A. Sloane_, Oct 26 2023
%E a(4) = 28025 from _Michael De Vlieger_, Oct 26 2023, who also reports that 5 does not appear in the first 2^24 terms of A366475.
%E a(5) from _Chai Wah Wu_, Oct 28 2023