1008 N的阶乘 mod P
输入N和P(P为质数),求N! Mod P = ? (Mod 就是求模 %)
例如:n = 10, P = 11,10! = 3628800
3628800 % 11 = 10
Input
两个数N,P,中间用空格隔开。(N < 10000, P < 10^9)
Output
输出N! mod P的结果。
Input示例
10 11
Output示例
10
一道基础题目,累计相乘,同时取模,代码如下:
while True:
try:
A, B = list(map(int, input().split()))
ans = 1
for i in range(2, A+1):
ans = (ans*i)%B
print(ans)
except EOFError:
break