Last active
August 3, 2017 13:36
-
-
Save tera3939/fd6a23e90d09f175f6eb966387fe03e3 to your computer and use it in GitHub Desktop.
分割統治法で階乗計算
This file contains 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
# -*- encoding: utf-8 -*- | |
def each_slice_2(f, iterator): | |
a = iterator.__iter__() | |
for i in a: | |
try: | |
j = a.__next__() | |
except: | |
j = 0 | |
yield f(i, j) | |
def fanc(n): | |
a = range(1, n-1) | |
while n > 0: | |
a = each_slice_2(lambda x, y: x * y if y != 0 else x, a) | |
n = n // 2 | |
return a.__next__() | |
def main(): | |
n = int(input()) | |
print(fanc(n)) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment