Skip to content

Instantly share code, notes, and snippets.

@igorvanloo
Created July 27, 2021 13:52
Show Gist options
  • Save igorvanloo/954873e469c5dee1496079ededb30370 to your computer and use it in GitHub Desktop.
Save igorvanloo/954873e469c5dee1496079ededb30370 to your computer and use it in GitHub Desktop.
Problem 743
def A(k,n):
total = 0
f0 = 1
modulo = 1000000007
power = pow(2, n//k, modulo)
for a in range(0, n//k + 1):
total = (total + (f0 * pow(power, k-2*a, modulo))) % modulo
f0 = (f0*(k-2*a)*(k-2*a-1)) % modulo
f0 = (f0*pow((a+1)**2, -1, modulo)) % modulo
return total
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment