# A function about prime gaps

I want to define a $f$ function on Mathematica such as this. $f[k]$ gives the smallest $m$ holds $2k=Prime[m+1]-Prime[m]$. For example,

$$f[1]=2$$ $$f[2]=4$$ $$f[3]=9$$ $$f[4]=24$$

How can i do that?

• I can't see an easy way of doing it. You'd have to build a table or do a While loop or something. I assume you're looking for an easier solution than that, yes? – barrycarter Jan 28 '16 at 14:57

The sequence $f[k]$ you are looking for is Sloane's A038664. There is Mathematica code given there by Harvey P. Dale.
With[{d=Differences[Prime[Range[50000]]]},