Problem A

Algebraic Teamwork

The great pioneers of group theory and linear algebra want to cooperate and join their theories. In group theory, permutations – also known as bijective functions – play an important role. For a finite set A, a function σ : A A is called a permutation of A if and only if there is some function ρ : A A with σ(ρ(a)) = a and ρ(σ(a)) = a   for all a A.

The other half of the new team – the experts on linear algebra – deal a lot with idempotent functions. They appear as projections when computing shadows in 3D games or as closure operators like the transitive closure, just to name a few examples. A function p : A A is called idempotent if and only if p(p(a)) = p(a)      for all a A.

To continue with their joined research, they need your help. The team is interested in non-idempotent permutations of a given finite set A. As a first step, they discovered that the result only depends on the set’s size. For a concrete size 1 ≤ n ≤ 105, they want you to compute the number of permutations on a set of cardinality n that are not idempotent.

Input

The input starts with the number t ≤ 100 of test cases. Then t lines follow, each containing the set’s size 1 ≤ n ≤ 105.

Output

Output one line for every test case containing the number modulo 1000000007 = (109 + 7) of non-idempotent permutations on a set of cardinality n.

Sample Input

Sample Output

3

1

2

2171

0

1

6425

解题:n!-1

 #include <bits/stdc++.h>
#define LL long long
using namespace std;
const int maxn = ;
const int md = 1e9+;
LL d[maxn];
int main(){
d[] = ;
for(int i = ; i < maxn; ++i)
d[i] = (i%md*d[i-])%md;
int x,ks;
scanf("%d",&ks);
while(ks--){
scanf("%d",&x);
printf("%lld\n",(d[x]+md-)%md);
}
return ;
}

CSUOJ 1525 Algebraic Teamwork的更多相关文章

  1. Teamwork[HDU4494]

    Teamwork Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Submi ...

  2. csuoj 1511: 残缺的棋盘

    http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1511 1511: 残缺的棋盘 时间限制: 1 Sec  内存限制: 128 MB 题目描述 输入 ...

  3. NBUT 1525 Cow Xor(01字典树+前缀思想)

    [1525] Cow Xor 时间限制: 2000 ms 内存限制: 65535 K 问题描述 农民约翰在喂奶牛的时候被另一个问题卡住了.他的所有N(1 <= N <= 100,000)个 ...

  4. 九度oj 1525 子串逆序打印

    原题链接:http://ac.jobdu.com/problem.php?pid=1525 字符串简单题,注意开有结尾有空格的情况否则pe or wa #include<algorithm> ...

  5. (博弈论)hdoj 1525 Euclid's Game

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1525 题目大意:Stan和Ollie在玩一个游戏,a和b两个数字,每次可以选择较大的数减去较小的数的若 ...

  6. hdu 4494 Teamwork 最小费用最大流

    Teamwork Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4494 ...

  7. csuoj 1354: Distinct Subsequences

    这个题是计算不同子序列的和: spoj上的那个同名的题是计算不同子序列的个数: 其实都差不多: 计算不同子序列的个数使用dp的思想: 从头往后扫一遍 如果当前的元素在以前没有出现过,那么dp[i]=d ...

  8. 九度OJ 1525 子串逆序打印 -- 2012年Google校园招聘笔试题目

    题目地址:http://ac.jobdu.com/problem.php?pid=1525 题目描述: 小明手中有很多字符串卡片,每个字符串中都包含有多个连续的空格,而且这些卡片在印刷的过程中将字符串 ...

  9. 【HDOJ】1525 Euclid's Game

    自己想明白的第一道博弈.首先a==b的时候肯定是先手赢: 然后当a>=2*b时,不妨假设a=nb+k, k<b,因此,不论后续怎么博弈,一定可以出现a=k, b=b的情况.因此,无论这个局 ...

随机推荐

  1. leetCode解题报告5道题(七)

    题目一:Interleaving String Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2 ...

  2. iOS 9 适配,我咋还没遇到这么多坑呢呀

    iOS 9 适配,我咋还没遇到这么多坑呢呀 太阳火神的漂亮人生 (http://blog.csdn.net/opengl_es) 本文遵循"署名-非商业用途-保持一致"创作公用协议 ...

  3. Kali linux 2016.2(Rolling)中metasploit的主机探测

    不多说,直接上干货! 1.活跃主机扫描 root@kali:~# ping -c 202.193.58.13 PING () bytes of data. bytes ttl= time=25.4 m ...

  4. <Sicily>数字反转

    一.题目描述 给定一个整数,请将该数各个位上数字反转得到一个新数.新数也应满足整数的常见形式,即除非给定的原数为零,否则反转后得到的新数的最高位数字不应为零(参见样例2). 二.输入 输入共 1 行, ...

  5. grvphviz && dot脚本语言

    安装graphviz 可去官网下载http://www.graphviz.org/download/下载之后按步骤安装 打开编辑器,创建*.dot文件,编辑dot脚本代码,保存. D:\>dot ...

  6. 隐藏div,文本框角圆滑,消除外边框

    #div_1 /*将div设置完成,并且隐藏,当需要的时候对其属性值进行修改*/ { height: 36px; width: 1099px; background-color: #F0DFDF; m ...

  7. mongodb 的 curd

        增:          db.表名.insert({name:'lisi',age:24});                                                  ...

  8. Rman备份异机恢复

    最后更新时间:2018/12/29 前置条件 已准备一台安装好Centos6+oracle11gr2 软件的服务器; 只安装了 oracle 数据库软件,需要手工创建以下目录: #环境变量 expor ...

  9. ArcGIS api for javascript——地图配置-增加一个调试控制台<

    描述 该示例展示了在应用中如何包含一个Dojo调试控制台.可以写信息到控制台来记录发生的事件和应用运行时设置的属性.当调试Internet Explorer浏览器的错误时这是极为有帮助的.(对Fire ...

  10. 【C语言】打印1到最大的n位数

    //打印1到最大的n位数 //输入数字n,按顺序打印出从1到最大的n位十进制数. 比方:输入3.则打印出1.2一直到最大的3位数999 #include <stdio.h> #includ ...