In this challenge we'll compute an infinite minimal admissible sequence.

The sequence for this challenge starts with a(1) = 1.

We continue this sequence by finding a(n) as the smallest possible number such that a(n) > a(n-1) and for every prime p, the set {a(i) mod p : 1 ≤ i ≤ n} has at most p-1 elements.

Write a program or function that takes positive integer n and outputs a(n). Shortest code in bytes wins.

Example:

a(6) is 19, rather than, say 17 because [1,3,7,9,13,19] (the previous terms) is admissible while [1,3,7,9,13,17] is not.

[1,3,7,9,13,17] is not admissible, because for the base 3, after taking the modulo of each term with 3, we obtain [1,0,1,0,1,2] which contains every non-negative number smaller than 3, our chosen base.

For [1,3,7,9,13,19] however, it would be impossible to come up with a base such that the list after modulo contains every non-negative integer smaller than such base.

Reference:

Testcases:

a(1) = 1
a(2) = 3
a(3) = 7
a(4) = 9
a(5) = 13
a(6) = 19
a(7) = 21
a(8) = 27
a(9) = 31
a(10) = 33
a(100) = 583

• Can we use 0-based index? – Leaky Nun Aug 14 '16 at 12:13
• Related. – Martin Ender Aug 14 '16 at 13:19
• @LeakyNun For this one, sure. – orlp Aug 14 '16 at 15:32

# Brachylog, 44 bytes

-:r:cit.


Try it online!

100 takes about a minute here, so be patient if you want to try 100.

### Predicate 0 (main predicate)

-:r:cit.
-:r:c     create array [, input-1, 1]
i    iterate:  as input, iterate (input-1) times, predicate 1
t.  last element is the output


### Predicate 1 (auxiliary predicate)

t<gX=:?rc.'(l:2eLg:.rz:%adlL)
t<                              last element of input < Temp
gX                            [Temp] = X
X=                           Assign a value to X, which assigns
a value to Temp
X :?rc.                      [Input,X] concatenated is output
.'(                )   The following about the output cannot
be proven:
l:2eL                   L is a number between 2 and length
of output, inclusive
Lg:.rz:%a           every element of output, taken modulo L,
dlL        after removing duplicates, has length L


## ES6, 91 bytes

(n,a=[i=1])=>a[n]||f(n,a.every((_,j)=>(j+=2)>new Set(b.map(e=>e%j)).size,b=[...a,+++])?b:a)


Zero-indexed. Due to its recursive nature, only works for the first 450 terms, but computes a(99)=583 almost instantly.