## Python 3.5 - 130 bytes ##

    from math import*
    def p(n,k,g):
     for i in range(1,n+1):k+=factorial(i-1)%i!=i-1
     for l in range(1,k):g+=gcd(k,l)<2      
     return g

If it's not acceptable to pass the function through as p(n,0,0) then +3 bytes.

This takes advantage of the fact that I use Wilson's theorem to check if a number is composite and have to call into the math module for the factorial function. Python 3.5 added a gcd function into the math module.

The first loop of the code will increment k by one if the number is composite and increment by 0 else-wise. (Although Wilson's theorem only holds for integers greater than 1, it treats 1 as prime, so allows us to exploit this).

The second loop will then loop over the range of number of composites and increment g only when the value of not pi and l are co-prime.

g is then the number of values less than or equal to the number of composite numbers less than or equal to n.