#JavaScript, 93 9191 87 bytes
n=>(g=x=>n-i?a[++x]|g[++x]|(h=(y,z)=>z?h(z,y%z):y)(x,c)<2?g(x):(a[c=x]=++ig[c=x]=++i,x>n)+g(2):0)(a=[i=c=2]i=c=2)
Try it onlineTry it online
n=> :Anonymous function taking the input as an argument via parameter n
(g=x=> :Main function g which takes the number we want to test as an argument via parameter x
n-i? :If n is greater than the iteration counter i then
a[++x] :Increment x and check if the array a has an element at that index
:(On the first iteration x will be the singleton array [2] which gets coerced to a number before being incremented)
| :Or
(h=(y,z)=>z?h(z,y%z):y)(x,c) :Helper function which returns the GCD of x and c, the last number in he sequence so far
<2 :If that's less than 2 then c & x are co-prime
? :If either of those checks are truthy then
g(x) :Call g again with the incremented value of x
:( :Else
a[c=x]=++i, :Assign x to c for the next iteration, increment the iteration counter and drop that value into the array at index x
x>n :Test if x is greater than the original input
)+g(2) :Add the result of running g again, with an initial value of 2
:0 :Else if n==i then return 0, add that to the final value and return the result
)(a=[i=c=2]) :Immediately call g with an initial value of [2] which also gets assigned to a and initiate i & c with a value of 2