CSU 1525: Algebraic Teamwork

题目:

InputOutputSample Input
3
1
2
2171
Sample Output
0
1
6425

题意:

求n个元素的置换中,有多少个不是幂等的

n个元素的置换有n!个,其中幂等的就只有1个,所以答案是n!-1

代码:

#include<iostream>
using namespace std;

int p = 1000000007;
long long fac[100001];

int main()
{
	fac[0] = 1;
	for (int i = 1; i <= 100000; i++)fac[i] = fac[i - 1] * i%p;
	int t, n;
	cin >> t;
	while (t--)
	{
		cin >> n;
		cout << (fac[n] + p - 1) % p << endl;
	}
	return 0;
}
/**********************************************************************
	Problem: 1525
	User: 3901140225
	Language: C++
	Result: AC
	Time:12 ms
	Memory:2800 kb
**********************************************************************/


猜你喜欢

转载自blog.csdn.net/nameofcsdn/article/details/80285688