-
-
Save neizod/5343612 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import cycle, izip | |
k, l, m, n, d = [int(raw_input()) for _ in range(5)] | |
dragons = [cycle([False] * (i-1) + [True]) for i in {k, l, m, n}] | |
print sum(any(next(izip(*dragons))) for _ in xrange(d)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import combinations | |
from functools import reduce | |
from fractions import gcd | |
lcm = lambda a, b: a * b // gcd(a, b) | |
odd = lambda n: n % 2 == 1 | |
def count_slap(set_dragons, nos_dragons, total=0): | |
for how_many, dragon in enumerate(set_dragons, 1): | |
for group in combinations(set_dragons, how_many): | |
if odd(how_many): | |
total += nos_dragons // reduce(lcm, group) | |
else: | |
total -= nos_dragons // reduce(lcm, group) | |
return total | |
def main(): | |
k, l, m, n, d = [int(raw_input()) for _ in range(5)] | |
print count_slap({k, l, m, n}, d) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment