Python 2, 67 65 bytes
f=lambda n,k=0,m=2,p=1:k/n*~-m or f(n,k+p%m*(`n`in`m`),m+1,p*m*m)
Test it on Ideone.
This uses a corollary of Wilson's theorem:
f=lambda n,k=0,m=2,p=1:k/n*~-m or f(n,k+p%m*(`n`in`m`),m+1,p*m*m)
Test it on Ideone.
This uses a corollary of Wilson's theorem: