Algebraic Teamwork

来源:互联网 发布:网络口意什么意思 编辑:程序博客网 时间:2024/05/14 08:32


Description

Input

Output

Sample Input

3122171

Sample Output

016425

HINT

1.permutation应该翻译成置换


2.

idempotent function:集合A中的每个元素的对应自己本身的映射

3.集合A有n个元素,那么non-idemponent permutations of a set A的个数为n!-1

4.ans=(n!-1)%(1e9+7)

5.在Visual C++中int型的范围-2147483648~2147483647,简单记忆为-2e9~2e9

6.a*b%c=(a%c*b%c)%c

7.f[n]=n!%c

f[1]=1%c

f[2]=2*1%c=(2%c*f[1])%c

f[3]=3*2*1%c=(3%c*f[2])%c

f[i]=i!%c=(i%c*f[i-1])%c

8.(a-b)%c=(a%c+c-b)%c

9.long long 双长整型 printf("%lld\n",ans); 简单记忆为9e18

10.__int64 of VC is not ANSI, but you can use long long for 64-bit integer

综上,ans=(n!-1)%(1e9+7)=(n!%(1e9+7)+1e9+7-1)%(1e9+7)=(f[n]+c-1)%c

#include<iostream>
#include<cstdio>
using namespace std;
long long g[100006];
const int x=1e9+7;
main()
{
 g[1]=1;
 for(int i=2;i<100006;i++)
 {
  g[i]=(i%x*g[i-1])%x;
 }
 int t,n;
 long long ans;
 scanf("%d",&t);
 while(t--)
 {
  scanf("%d",&n);
  ans=(g[n]%x+x-1)%x;
  printf("%lld\n",ans);
 }
}

0 0
原创粉丝点击