Definition
- Two integers are coprime if they share no positive common divisors other than
1
.
a(1) = 1
a(2) = 2
a(n)
is the mallestsmallest positive integer which is coprime to the a(n-1)
and a(n-2)
and has not yet appeared, for integer n >= 3
.
Task
- Given positive integer
n
, output/print a(n)
.
Example
a(11) = 6
because 6
is coprime with the last two predecessors (namely, 11
and 13
) and 6
has not appeared before.
Notes
- Note that the sequence is not ascending, meaning that an element can be smaller than its predecessor.
Specs
Testcases
n a(n)
1 1
2 2
3 3
4 5
5 4
6 7
7 9
8 8
9 11
10 13
11 6
12 17
13 19
14 10
15 21
16 23
17 16
18 15
19 29
20 14
100 139
1000 1355
10000 13387
100000 133361
Scoring
- Since coprime means that the two numbers share only one divisor (
1
), and 1
is a small number, your code should be as small as possible in terms of byte-count.
References