2018 icpc网络赛-Nanjing 题解 A An Olympian Math Problem

版权声明: https://blog.csdn.net/weixin_39778570/article/details/82321012

题目链接:https://nanti.jisuanke.com/t/30990
1000ms 65536K
Alice, a student of grade 66, is thinking about an Olympian Math problem, but she feels so despair that she cries. And her classmate, Bob, has no idea about the problem. Thus he wants you to help him. The problem is:

We denote k!k!:

k! = 1 \times 2 \times \cdots \times (k - 1) \times kk!=1×2×⋯×(k−1)×k

We denote SS:

S = 1 \times 1! + 2 \times 2! + \cdots +S=1×1!+2×2!+⋯+
(n - 1) \times (n-1)!(n−1)×(n−1)!

Then SS module nn is __

You are given an integer nn.

You have to calculate SS modulo nn.

(n-1)(n-1)! = n!-(n-1)!
S = n!-1
S mod n = n-1

猜你喜欢

转载自blog.csdn.net/weixin_39778570/article/details/82321012