Calculate the hypergeometric p-value when p = f(k; N,K,n) is already known.

def get_hgp(p, k, N, K, n):
    """Calculate the hypergeometric p-value when p = f(k; N,K,n) is already known.
    """
    pval = p
    while k < min(K, n):
        p *= (float((n-k)*(K-k) / float((k+1)*(N-K-n+k+1))))
        pval += p
        k += 1
    return pval