Skip to content

Instantly share code, notes, and snippets.

@jakab922
Created September 26, 2017 05:12
Show Gist options
  • Save jakab922/17789a03f57da77f5b18f4fdbeb90f61 to your computer and use it in GitHub Desktop.
Save jakab922/17789a03f57da77f5b18f4fdbeb90f61 to your computer and use it in GitHub Desktop.
C1/2
from fractions import gcd
from collections import defaultdict as dd
n, k = map(int, raw_input().strip().split())
ais = filter(lambda x: x != 0, map(int, raw_input().strip().split()))
n = len(ais)
mod = 10 ** 9 + 7
curr = {1: 1}
for ai in ais:
nxt = dd(int)
print "curr: %s" % (curr,)
print "ai: %s" % (ai,)
for key in curr:
for el in (1, ai):
nkey = key * gcd(k / key, el)
nxt[nkey] = (nxt[nkey] + el * curr[key]) % mod
curr = nxt
print curr[k] if k in curr else 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment