【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 ...
随机推荐
- jquery获取transform里面的值
用transform的translateX写了一个侧滑效果,如何获取它改变的值是多少呢? 获取translateX值的方法: $('div').css("transform").r ...
- H5跟ios、android交互跟数据对接
需求: APP要用H5页面做展示,而且要获取到对应的商品ID,用户点击H5页面跳回APP原生页面. 方法: 先要判断用户是ios还是android设备(这里只考虑ios跟android,因为它俩写法还 ...
- axios 发 post 请求,后端接收不到参数的解决方案
问题场景 场景很简单,就是一个正常 axios post 请求: axios({ headers: { 'deviceCode': 'A95ZEF1-47B5-AC90BF3' }, method: ...
- Eclipse SWT
Reference: http://www.eclipse.org/swt/ http://www.functionx.com/win32/Lesson01.htm http://www.win32d ...
- 用Webstorm 运行React-native 工程时,出错:xcrun: error: unable to find utility "instruments", not a developer tool or in PATH
解决方法:在 终端执行如下命令 sudo xcode-select -s /Applications/Xcode.app/Contents/Developer/ 注意:前提是你已经安装了xcode
- Bootstrap后台管理模板调研
Bootstrap后台管理模板调研 SB Admin 2(推荐) SB Admin 2是一款开源的基于Bootstrap搭建的后台管理模板,简约,易用.没有复杂的组件和花炫的设计,很质朴,但较为美观. ...
- Python——追加学习笔记(一)
映射.字典 ## 映射类型内建函数 * dict Error: Python核心编程(第二版)p170 >>> dict([['x', 1], ['y', 2]]) {'y': 2, ...
- matlab中换行
若在命令窗口中,如果一条语句已经写完,需要换行,可以用"Shift+Enter", 如果一条语句没写完就想换行,可以使用"...+Enter".
- C++11之 Move semantics(移动语义)(转)
转https://blog.csdn.net/wangshubo1989/article/details/49748703 按值传递的意义是什么? 当一个函数的参数按值传递时,这就会进行拷贝.当然,编 ...
- jquery.dataTables列中内容居中问题?求解?
.table > tbody > tr > td { vertical-align: middle; }