Smallest positive integer which is coprime to the last two predecessors and has not yet appeared; a(1)=1, a(2)=2 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 smallest positive integer which is coprime to the a(n-1) and a(n-2) and has not yet appeared, for integer n &gt;= 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


You must use 1-indexed.


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


OEIS A084937
Python 3.5, 160 141 126 124 121 109 bytes



This is a simple implementation of the sequence's definition. Golfing suggestions welcome.

Edit: -17 bytes thanks to Leaky Nun. -9 bytes thanks to Peter Taylor. -6 bytes thanks to Sp3000 and switching to Python 3.5. 

import math;f=lambda n,r=[2,1],c=3:n&lt;2and r[1]or(c in r)+math.gcd(c,r[0]*r[1])&lt;2and f(n-1,[c]+r)or f(n,r,c+1)


Ungolfing:

import math
def f(n, r=[2,1], c=3):
    if n&lt;2:
        return r[1]
    elif (c in r) + math.gcd(c,r[0]*r[1]) &lt; 2:
        return f(n-1, [c]+r)
    else:
        return f(n, r, c+1)