Submission #19916

# Submission time Handle Problem Language Result Execution time Memory
19916 2016-02-25T07:04:46 Z xdoju 순열 (kriii4_T) C++14
100 / 100
845 ms 1084 KB
#include <stdio.h>

const int MOD = 1000000007;

int mul(int x, int y){ return (long long)x * y % MOD; }

int power(int x, int y){
  if(y == 0) return 1;

  int r = power(x, y / 2);
  r = mul(r, r);
  if(y % 2 == 1) r = mul(r, x);
  return r;
}

int modinv(int x){
  return power(x, MOD - 2);
}

int main(){
  int N, K; scanf("%d%d", &N, &K);

  int v = 1;
  for(int i = 1; i <= N + 1; i++) v = mul(v, i); // fac(N + 1)

  v = mul(v, N + 1);

  int ans = 0;

  for(int k = 1; k <= N; k++){
    v = mul(v, k);
    v = mul(v, modinv(k + 1));
    v = mul(v, N - k + 1);
    v = mul(v, modinv(N - k + 2));

    if(k >= K + 1) ans = (ans + v) % MOD;
  }

  printf("%d\n", ans);
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 1084 KB Output is correct
2 Correct 0 ms 1084 KB Output is correct
3 Correct 0 ms 1084 KB Output is correct
4 Correct 0 ms 1084 KB Output is correct
5 Correct 0 ms 1084 KB Output is correct
6 Correct 0 ms 1084 KB Output is correct
7 Correct 0 ms 1084 KB Output is correct
8 Correct 0 ms 1084 KB Output is correct
9 Correct 0 ms 1084 KB Output is correct
10 Correct 0 ms 1084 KB Output is correct
11 Correct 0 ms 1084 KB Output is correct
12 Correct 0 ms 1084 KB Output is correct
13 Correct 0 ms 1084 KB Output is correct
14 Correct 0 ms 1084 KB Output is correct
15 Correct 0 ms 1084 KB Output is correct
16 Correct 0 ms 1084 KB Output is correct
17 Correct 0 ms 1084 KB Output is correct
18 Correct 0 ms 1084 KB Output is correct
19 Correct 0 ms 1084 KB Output is correct
20 Correct 0 ms 1084 KB Output is correct
21 Correct 0 ms 1084 KB Output is correct
22 Correct 0 ms 1084 KB Output is correct
23 Correct 0 ms 1084 KB Output is correct
24 Correct 0 ms 1084 KB Output is correct
25 Correct 0 ms 1084 KB Output is correct
26 Correct 0 ms 1084 KB Output is correct
27 Correct 0 ms 1084 KB Output is correct
28 Correct 0 ms 1084 KB Output is correct
29 Correct 0 ms 1084 KB Output is correct
30 Correct 1 ms 1084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 843 ms 1084 KB Output is correct
2 Correct 703 ms 1084 KB Output is correct
3 Correct 714 ms 1084 KB Output is correct
4 Correct 154 ms 1084 KB Output is correct
5 Correct 161 ms 1084 KB Output is correct
6 Correct 714 ms 1084 KB Output is correct
7 Correct 779 ms 1084 KB Output is correct
8 Correct 439 ms 1084 KB Output is correct
9 Correct 201 ms 1084 KB Output is correct
10 Correct 89 ms 1084 KB Output is correct
11 Correct 260 ms 1084 KB Output is correct
12 Correct 538 ms 1084 KB Output is correct
13 Correct 678 ms 1084 KB Output is correct
14 Correct 838 ms 1084 KB Output is correct
15 Correct 484 ms 1084 KB Output is correct
16 Correct 503 ms 1084 KB Output is correct
17 Correct 543 ms 1084 KB Output is correct
18 Correct 318 ms 1084 KB Output is correct
19 Correct 294 ms 1084 KB Output is correct
20 Correct 659 ms 1084 KB Output is correct
21 Correct 219 ms 1084 KB Output is correct
22 Correct 686 ms 1084 KB Output is correct
23 Correct 573 ms 1084 KB Output is correct
24 Correct 140 ms 1084 KB Output is correct
25 Correct 734 ms 1084 KB Output is correct
26 Correct 463 ms 1084 KB Output is correct
27 Correct 214 ms 1084 KB Output is correct
28 Correct 841 ms 1084 KB Output is correct
29 Correct 845 ms 1084 KB Output is correct
30 Correct 840 ms 1084 KB Output is correct