Skip to content

Instantly share code, notes, and snippets.

@luliangce
Created April 26, 2019 16:55
Show Gist options
  • Select an option

  • Save luliangce/04b759cc89aee74ed8d6e7cc2f097e74 to your computer and use it in GitHub Desktop.

Select an option

Save luliangce/04b759cc89aee74ed8d6e7cc2f097e74 to your computer and use it in GitHub Desktop.
from functools import reduce
def rm(x, r):
_min = reduce(lambda x, y: x*y, x)
circulate, rest = divmod(r, _min)
r = common = 0
for i in range(1, _min):
for j in x:
if i % j == 0:
break
else:
common += 1
if i <= rest:
r += 1
return common*circulate+r
if __name__ == "__main__":
x = [2, 5, 7]
r = 10000
a = rm(x, r)
c = 0
for i in range(1, r):
for j in x:
if i % j == 0:
break
else:
c += 1
print(a)
assert c == a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment