Introduction
The EKG sequence begins with 1 and 2, then the rule is that the next term is the smallest positive integer not already in the sequence and whose common factor with the last term is greater than 1 (they are not coprimes).
The first terms are:
1, 2, 4, 6, 3, 9, 12, 8, 10, 5, 15, ...
It's called EKG because the graph of its terms is quite similar to an EKG.
It's sequence A064413 in the OEIS.
Challenge
You have to write a function which takes an integer n as input and outputs how many of the n first terms of the sequence are greater than n.
As the sequence's rule begins with the third term, the input integer has to be greater or equal to 3. For example, given input 10
the output is 1
because the 7th term is 12
and none of the other first ten terms exceed 10.
Test cases
3 -> 1
10 -> 1
100 -> 9
1000 -> 70
Rules
- For integers lower than 3, the function may output 0 or an error code.
- No other particular rules except: it's code golf, the shorter the better!
1
being the 0th term of the sequence and therefor making, for example,15
the 10th term, rather than5
? \$\endgroup\$