Skip to content

Instantly share code, notes, and snippets.

@tera3939
Last active August 3, 2017 13:36
Show Gist options
  • Save tera3939/fd6a23e90d09f175f6eb966387fe03e3 to your computer and use it in GitHub Desktop.
Save tera3939/fd6a23e90d09f175f6eb966387fe03e3 to your computer and use it in GitHub Desktop.
分割統治法で階乗計算
# -*- 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