(n, k)
return s // ifac(k)
Stirling number of the second kind.
Stirling number of the second kind.
Stirling number of the second kind .
def stirling2(n, k):
    """
    Stirling number of the second kind.
    """
    if n < 0 or k < 0:
        raise ValueError
    if k >= n:
        return MPZ(n == k)
    if k <= 1:
        return MPZ(k == 1)
    s = MPZ_ZERO
    t = MPZ_ONE
    for j in xrange(k+1):
        if (k + j) & 1:
            s -= t * MPZ(j)**n
        else:
            s += t * MPZ(j)**n
        t = t * (k - j) // (j + 1)
    return s // ifac(k)
def stirling2 ( n , k ) : if n < 0 or k < 0 : raise ValueError if k >= n : return MPZ ( n == k ) if k <= 1 : return MPZ ( k == 1 ) s = MPZ_ZERO t = MPZ_ONE for j in xrange ( k + 1 ) : if ( k + j ) & 1 : s -= t * MPZ ( j ) ** n else : s += t * MPZ ( j ) ** n t = t * ( k - j ) // ( j + 1 ) return s // ifac ( k )