【2018 ICPC南京网络赛 A】An Olympian Math Problem(数论题)
Alice, a student of grade 6, is thinking about an Olympian Math problem, but she feels so despair that she cries. And her classmate, Bob, has no idea about the problem. Thus he wants you to help him. The problem is:
We denote k!:
k! = 1 × 2 × ⋯ × (k - 1) × k
We denote S:
S = 1 × 1! + 2 × 2! + ⋯ + (n−1) × (n−1)!
Then S module n is ____________
You are given an integer n.
You have to calculate S modulo n.
Input
The first line contains an integer T(T≤1000), denoting the number of test cases.
For each test case, there is a line which has an integer n.
It is guaranteed that 2 ≤ n ≤ 1018.
Output
For each test case, print an integer S modulo n.
Hint
The first test is: S = 1 × 1! = 1, and 1 modulo 2 is 1.
The second test is: S = 1 × 1! + 2 × 2! = 5 , and 5 modulo 3 is 2.
样例输入
2
2
3
样例输出
1
2
题意:
已知S = 1 × 1! + 2 × 2! + ⋯ + (n−1) × (n−1)!,求S%n的值。
思路:
直接上结论吧,S%n=n-1
#include<iostream>
using namespace std;
typedef long long ll;
int main()
{
int t;
cin>>t;
while(t--)
{
ll n;
cin>>n;
cout<<n-<<endl;
}
return ;
}
【2018 ICPC南京网络赛 A】An Olympian Math Problem(数论题)的更多相关文章
- 2018 ICPC南京网络赛 L Magical Girl Haze 题解
大致题意: 给定一个n个点m条边的图,在可以把路径上至多k条边的权值变为0的情况下,求S到T的最短路. 数据规模: N≤100000,M≤200000,K≤10 建一个立体的图,有k层,每一层是一份原 ...
- 2018 ICPC南京网络赛 Set(字典树 + 合并 + lazy更新)
题解:n个集合,你要进行m个操作.总共有3种操作.第一种,合并两个集合x和y.第二张,把特定的集合里面所有的数字加一.第三种,询问在某个集合里面,对于所有数字对2的k次方取模后,有多少个数字等于x. ...
- 2018 ICPC 沈阳网络赛
2018 ICPC 沈阳网络赛 Call of Accepted 题目描述:求一个算式的最大值与最小值. solution 按普通算式计算方法做,只不过要同时记住最大值和最小值而已. Convex H ...
- 2018 ICPC 徐州网络赛
2018 ICPC 徐州网络赛 A. Hard to prepare 题目描述:\(n\)个数围成一个环,每个数是\(0\)~\(2^k-1\),相邻两个数的同或值不为零,问方案数. solution ...
- 2018 ICPC 焦作网络赛 E.Jiu Yuan Wants to Eat
题意:四个操作,区间加,区间每个数乘,区间的数变成 2^64-1-x,求区间和. 题解:2^64-1-x=(2^64-1)-x 因为模数为2^64,-x%2^64=-1*x%2^64 由负数取模的性质 ...
- 2013 ACM/ICPC 南京网络赛F题
题意:给出一个4×4的点阵,连接相邻点可以构成一个九宫格,每个小格边长为1.从没有边的点阵开始,两人轮流向点阵中加边,如果加入的边构成了新的边长为1的小正方形,则加边的人得分.构成几个得几分,最终完成 ...
- 2018 icpc 青岛网络赛 J.Press the Button
Press the Button Time Limit: 1 Second Memory Limit: 131072 KB BaoBao and DreamGrid are playing ...
- 2018 ICPC青岛网络赛 B. Red Black Tree(倍增lca好题)
BaoBao has just found a rooted tree with n vertices and (n-1) weighted edges in his backyard. Among ...
- 2018 icpc 徐州网络赛 F Features Track
这个题,我也没想过我这样直接就过了 #include<bits/stdc++.h> using namespace std; ; typedef pair<int,int> p ...
随机推荐
- Java 条件语句
1.if...else 一个 if 语句包含一个布尔表达式和一条或多条语句. if(布尔表达式) { //如果布尔表达式为true将执行的语句 }else{ //如果布尔表达式为false将执行的语句 ...
- (三)css之浮动&定位
众所周知,一个页面可能包含多个div,如何对这些div进行排列,以便具有较好的显示效果呢? css提供了浮动和定位两个属性进行div的排列,下面主要针对浮动和定位进行详细地阐述. (一)何为浮动? 浮 ...
- 面试基础(二)-mem函数
常考的函数有下面三个,memset,memcpy,memmove,一定要记住三个函数的函数原型,熟记返回值类型和参数类型,当然也不能忘记参数检查 memset #include<iostre ...
- FTP FileZilla Server 本地加密C# 实现
最近公司要做一个资料管理模块,因系统是C/S架构,原来小文件都是直接使用7Z压缩后保存到SQL Server数据库 而资料管理模块也就是文件上传,下载加权限管理,考虑文件较多,还可能比较大,所以打算在 ...
- Implementation: Quick Sort 2014-08-19
#include <stdio.h> void print(int *a, int start , int end); void quick_sort(int *a, int start, ...
- jQuery Custom PopUp Window
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- jQuery登录倒计时
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script sr ...
- http状态码汇总及代表意思
成功2×× 成功处理了请求的状态码.200 服务器已成功处理了请求并提供了请求的网页.204 服务器成功处理了请求,但没有返回任何内容. 重定向3×× 每次请求中使用重定向不要超过 5 次.301 请 ...
- Eclipse Equinox DS(Declarative Service)
Equinox DS's METE-INF/MANIFEST.MF Manifest-Version: 1.0 Lazy-ManifestFilter: (Service-Component=*) B ...
- Infor SyteLine创建一个数据维护窗口
上次有在SyteLine解决一个问题<匹配与显示中文说明> http://www.cnblogs.com/insus/p/3396541.html .这些数据需要数据库管理员在数据库才能维 ...