Skip to main content
5 of 9
added 214 characters in body
Dennis
  • 210.6k
  • 41
  • 370
  • 825

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:

corollary of Wilson's theorem

Dennis
  • 210.6k
  • 41
  • 370
  • 825