-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11401.py
More file actions
67 lines (46 loc) · 1017 Bytes
/
11401.py
File metadata and controls
67 lines (46 loc) · 1017 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
'''
11401번
제출
맞은 사람
숏코딩
재채점
채점 현황
내 제출
강의
질문 검색
이항 계수 3 분류
시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 256 MB 10076 3959 2831 44.604%
문제
자연수 과 정수 가 주어졌을 때 이항 계수
를 1,000,000,007로 나눈 나머지를 구하는 프로그램을 작성하시오.
입력
첫째 줄에 과 가 주어진다. (1 ≤ ≤ 4,000,000, 0 ≤ ≤ )
출력
를 1,000,000,007로 나눈 나머지를 출력한다.
예제 입력 1
5 2
예제 출력 1
10
'''
import sys
MOD = 1000000007
def power(x, y):
ans = 1
while y > 0:
if y % 2 == 1:
ans = (ans*x) % MOD
x = (x*x) % MOD
y //= 2
return ans
def fac(n):
ans = 1
for i in range(2, n+1):
ans = (ans*i) % MOD
return ans
n, k = map(int, input().split())
if n == k or k == 0:
print(1)
exit(0)
a, b, c = fac(n), fac(k), fac(n-k)
print((a*power(b*c, MOD-2)) % MOD)