Skip to content

Instantly share code, notes, and snippets.

@haiiro-shimeji
Last active August 12, 2019 02:00
Show Gist options
  • Save haiiro-shimeji/2819d992546032001384a155ad8d96fd to your computer and use it in GitHub Desktop.
Save haiiro-shimeji/2819d992546032001384a155ad8d96fd to your computer and use it in GitHub Desktop.
""" abc055_b """
import sys
from functools import reduce
H = pow(10, 9) + 7
def _main():
_n = int(sys.stdin.readline())
# N! = aH + b
# (N+1)! = a'H + b'
#
# (N+1) * N! = aH(N+1) + b(N+1)
# = aH(N+1) + int(b(N+1)/H) * H + b(N+1) % H
# a' = a(N+1) + int(b(N+1)/H)
# b' = b(N+1) % H
#
_b = reduce(lambda b, n: (b * n) % H, range(1, _n + 1), 1)
print(_b)
if __name__ == '__main__':
_main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment