Skip to main content
8 of 8
Commonmark migration

JavaScript, 93 91 87 bytes

Throws an overflow error for 0 or 1, outputs 0 for 2.

n=>(g=x=>n-i?g[++x]|(h=(y,z)=>z?h(z,y%z):y)(x,c)<2?g(x):(g[c=x]=++i,x>n)+g(2):0)(i=c=2)

Try it online

Shaggy
  • 43.5k
  • 4
  • 36
  • 94