ph
0830 commoncode 문서 원본 보기
←
0830 commoncode
다음으로 이동:
둘러보기
,
검색
문서 편집 작업을 수행할 권한이 없습니다. 다음 이유를 확인해주세요:
요청한 작업은 다음 권한을 가진 사용자에게 제한됩니다:
사용자
.
문서의 원본을 보거나 복사할 수 있습니다.
$$ \frac{(a+b+c+\cdots+z)!}{a!b!c!\cdots z!} \pmod p \text{ where } p \text{ is a prime}$$ Above value is always integer. Refer [https://math.stackexchange.com/questions/2158/division-of-factorials the proofs]. The key observation is that the product of \(n\) consecutive integers is divisible by \(n!\).<ref> This can be proved by induction. [https://math.stackexchange.com/a/2171/64186]. And maybe possible by group theory</ref> <pre> p = int(1e9)+7 #example. this is a prime number def anmodp(a, n): # a^n mod p if n==1: return a%p tmp = anmodp(a, n/2) if n%2==1: #odd return (a*(tmp**2))%p else: return (tmp**2)%p def fac(n): # n! mod p k = 1 for i in range(2, n+1): k *= i k %= p return k def invfac(n): # 1/(n!) (mod p) return anmodp(fac(n), p-2) #euler totient def comb(x): # input = int array s = sum(x) ans = fac(s) for i in x: ans *= invfac(i) return ans % p </pre> <references/> <disqus/>
0830 commoncode
문서로 돌아갑니다.