Advertisement
Guest User

Untitled

a guest
Nov 24th, 2014
358
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.23 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #define llong long long
  4.  
  5. #define pb push_back
  6. #define mp make_pair
  7.  
  8. const int INF = (int) 5e8 + 3;
  9. const int MXN = (int) 1e6 + 7;
  10.  
  11. using namespace std;
  12.  
  13. int n, x, y;
  14. int f[MXN], rev[MXN];
  15.  
  16. int binpow(int a, int b) {
  17.     int res = 1;
  18.     while (b) {
  19.         if (b & 1)
  20.             res = (res * 1LL * a) % INF;
  21.  
  22.         a = (1LL * a * a) % INF;
  23.         b >>= 1;
  24.     }
  25.     return res;
  26. }
  27.  
  28. int calc(int a, int b) {
  29.     if (b > a) return 0;
  30.     int res = f[a];
  31.     res = (res * 1LL * rev[b]) % INF;
  32.     res = (res * 1LL * rev[a - b]) % INF;
  33.     return res;
  34. }
  35.  
  36. int main() {
  37.     f[0] = rev[0] = 1;
  38.     for (int i = 1; i < MXN; i++) {
  39.         f[i] = (f[i - 1] * 1LL * i) % INF;
  40.         rev[i] = binpow(f[i], INF - 2);
  41.     }
  42.     scanf("%d%d%d", &n, &x, &y);
  43.     if (x < 0) x = -x;
  44.     if (y < 0) y = -y;
  45.  
  46.     int ans = 0;
  47.     for (int h = x; h <= n; h += 2) {
  48.         int v = n - h;
  49.         if (v < y || (v - y) % 2 == 1 || h + v != n) continue;
  50.         int cur = (1LL * calc(h, (h - x) / 2) * calc(v, (v - y) / 2)) % INF;
  51.             cur = (1LL * cur * calc(n, h)) % INF;
  52.  
  53.         ans += cur % INF;
  54.         if (ans >= INF) ans -= INF;
  55.     }
  56.     printf("%d", ans);
  57.     return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement