Created
April 26, 2019 16:55
-
-
Save luliangce/04b759cc89aee74ed8d6e7cc2f097e74 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 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