Skip to content

Instantly share code, notes, and snippets.

@asuka-mirai
Created September 17, 2017 06:21
Show Gist options
  • Save asuka-mirai/a28b3338a41207844d60a2c47939062e to your computer and use it in GitHub Desktop.
Save asuka-mirai/a28b3338a41207844d60a2c47939062e to your computer and use it in GitHub Desktop.
from math import lgamma, exp, log
lfact = lambda n: lgamma(n + 1)
lcomb = lambda n, r: lfact(n) - lfact(n - r) - lfact(r)
n, d = map(int, input().split())
x, y = map(abs, map(int, input().split()))
if x % d != 0 or y % d != 0:
print('0')
exit(0)
x //= d
y //= d
r = 0
for u in range(n + 1):
v = n - u
if u - x < 0 or (u - x) % 2 != 0:
continue
if v - y < 0 or (v - y) % 2 != 0:
continue
t = lcomb(n, u) - 2*n * log(2)
t += lcomb(u, x + (u - x) // 2)
t += lcomb(v, y + (v - y) // 2)
r += exp(t)
print(r)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment