4424: Permutations
Submit your solution Discuss this problem Best solutions |
Description
Given N distinct elements, how many permutations we can get from all the possible subset of the elements?Input
The first line is an integer T that stands for the number of test cases. Then T line follow and each line is a test case consisted of an integer N. Constraints: T is in the range of [0, 10000] N is in the range of [0, 8000000]Output
For each case output the answer modulo 1000000007 in a single line.Sample Input
5 0 1 2 3 4Sample Output
0 1 4 15 64Author
baihacker
题解容易得出递推公式:f ( n ) = ( 1 + f( n-1 ) ) * n ;
代码如下:
#include<cstdio>
#include<cstring>
#include<set>
#include<iostream>
#include<map>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
#include<cctype>
#include<algorithm>
#define inff 0x3fffffff
#define nn 8100000
#define mod 1000000007
typedef long long LL;
using namespace std;
LL ans[nn];
int main()
{
int i;
ans[0]=0;
for(i=1;i<=8000000;i++)
{
ans[i]=((ans[i-1]+1)*i)%mod;
}
int t,n;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
printf("%lld\n",ans[n]);
}
return 0;
}