CSUOJ 1525 Algebraic Teamwork

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

 1 #include <bits/stdc++.h>
 2 #define LL long long
 3 using namespace std;
 4 const int maxn = 100010;
 5 const int md = 1e9+7;
 6 LL d[maxn];
 7 int main(){
 8     d[0] = 1;
 9     for(int i = 1; i < maxn; ++i)
10         d[i] = (i%md*d[i-1])%md;
11     int x,ks;
12     scanf("%d",&ks);
13     while(ks--){
14         scanf("%d",&x);
15         printf("%lld\n",(d[x]+md-1)%md);
16     }
17     return 0;
18 }

时间: 2024-08-27 04:43:47

CSUOJ 1525 Algebraic Teamwork的相关文章

GCPC2014 A Algebraic Teamwork

题意:其实就是要你求排列数. 解题思路:(n!-1)%1000000009 解题代码: 1 #include <iostream> 2 #include <string.h> 3 #include <stdio.h> 4 5 using namespace std; 6 typedef long long LL; 7 #define M 1000000007 8 #define maxn 100005 9 int n,m,p; 10 LL c[maxn]; 11 LL

hdu 4494 Teamwork 最小费用最大流

Teamwork Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4494 Description Some locations in city A has been destroyed in the fierce battle. So the government decides to send some workers to repair these location

Visualization of Detail Point Set by Local Algebraic Sphere Fitting

Refers to Dynamic Sampling and Rendering of Algebraic Point Set Surfaces Growing Least Squares for the Analysis of Manifolds in Scale-Space

hdu 1525 Euclid&#39;s Game 博弈

Euclid's Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2219    Accepted Submission(s): 1000 Problem Description Two players, Stan and Ollie, play, starting with two natural numbers. Stan

CSUOJ 1010 Water Drinking

Description The Happy Desert is full of sands. There is only a kind of animal called camel living on the Happy Desert. ‘Cause they live here, they need water here. Fortunately, they find a pond which is full of water in the east corner of the desert.

CSUOJ 1217 奇数个的那个数

Description 给定些数字,这些数中只有一个数出现了奇数次,找出这个数. Input 每组数据第一行n表示数字个数,1 <= n <= 2 ^ 18 且 n % 2 == 1. 接下来n行每行一个32位有符号整数. Output 出现奇数次那个数,每组数据对应一行. Sample Input 5 1 1 2 2 3 7 1 2 1 2 2 3 3 Sample Output 3 2 看了大神的代码 使用位运算o(╯□╰)o 1 # include <stdio.h> 2 i

Aizu 2164 CSUOJ 1436 Revenge of the Round Table

dp套一个burnside的壳子核心还是dpdp[i]表示有i个循环节时的染色方案数注意在dp的时候,不需要考虑重构的问题因为burnside会解决重构的问题dpA[i][j]表示以A开头,长度为i,结尾为j个A的合法方案数dpB[i][j]表示以B开头,长度为i,结尾为j个A的合法方案数接下来我们用dpA,dpB来计算dp[i]显然对于所有的dpB[i][1~k]都是满足dp[i]的因为它表示以B开头,以A结尾的染色方案,且结尾没有超过k个另外还有一部分就是以A开头的了假设我们在整个串的最前面

LightOJ 1070 Algebraic Problem (推导+矩阵快速幂)

题目链接:LightOJ 1070 Algebraic Problem 题意:已知a+b和ab的值求a^n+b^n.结果模2^64. 思路: 1.找递推式 得到递推式之后就是矩阵快速幂了 注意:模2^64,定义成unsigned long long 类型,因为无符号类型超过最大范围的数与该数%最大范围 的效果是一样的. AC代码: #include<stdio.h> #include<string.h> #define LL unsigned long long struct Ma

csuoj 1511: 残缺的棋盘

http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1511 1511: 残缺的棋盘 时间限制: 1 Sec  内存限制: 128 MB 题目描述 输入 输入包含不超过10000 组数据.每组数据包含6个整数r1, c1, r2, c2, r3, c3 (1<=r1, c1, r2, c2, r3, c3<=8). 三个格子A, B, C保证各不相同. 输出 对于每组数据,输出测试点编号和最少步数. 样例输入 1 1 8 7 5 6 1 1 3 3