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.
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.
3 -> 1
10 -> 1
100 -> 9
1000 -> 70
- 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!