计蒜客 30990.An Olympian Math Problem-数学公式题 (ACM-ICPC 2018 南京赛区网络预赛 A)
- 54.28%
- 1000ms
- 65536K
Alice, a student of grade 66, 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!:
k! = 1 \times 2 \times \cdots \times (k - 1) \times kk!=1×2×⋯×(k−1)×k
We denote SS:
S = 1 \times 1! + 2 \times 2! + \cdots +S=1×1!+2×2!+⋯+
(n - 1) \times (n-1)!(n−1)×(n−1)!
Then SS module nn is ____________
You are given an integer nn.
You have to calculate SS modulo nn.
Input
The first line contains an integer T(T \le 1000)T(T≤1000), denoting the number of test cases.
For each test case, there is a line which has an integer nn.
It is guaranteed that 2 \le n\le 10^{18}2≤n≤1018.
Output
For each test case, print an integer SS modulo nn.
Hint
The first test is: S = 1\times 1!= 1S=1×1!=1, and 11 modulo 22 is 11.
The second test is: S = 1\times 1!+2 \times 2!= 5S=1×1!+2×2!=5 , and 55 modulo 33 is 22.
样例输入复制
2
2
3
样例输出复制
1
2
题目来源
题意很好理解。
直接代码
代码:
//A-数学公式
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<deque>
#include<iomanip>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
using namespace std;
typedef long long ll; const double PI=acos(-1.0);
const double eps=1e-;
const ll mod=1e9+;
const int inf=0x3f3f3f3f;
const int maxn=1e5+;
const int maxm=+;
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//公式为1*1!+2*2!+3*3!+...+n*n!=(n+1)!-1,本题为(n!-1)%n
//因为n!-1=(n-1)*n-1=(n-2)*n+n-1,所以[(n-2)*n+(n-1)]%n=n-1
//因n*n!=(n+1-1)n!=(n+1)n!-n!=(n+1)!-n!
//所以:1*1!=2!-1!
//2*2!=3!-2!
//3*3!=4!-3!
//.
//n*n!=(n+1)!-n!
//相加后有:1*1!+2*2!+3*3!+.+n*n!=(n+1)!-1
//1*1!+2*2!+3*3!+.+n*n!=(n+1)!-1
//把最后一项拆开来,变成(n+1-1)n!=(n+1)n!-n! int main()
{
int t;
cin>>t;
while(t--){
ll n;
cin>>n;
cout<<n-<<endl;
}
}
溜了,一会贴一下线段树的题目。
计蒜客 30990.An Olympian Math Problem-数学公式题 (ACM-ICPC 2018 南京赛区网络预赛 A)的更多相关文章
- 计蒜客 30990 - An Olympian Math Problem - [简单数学题][2018ICPC南京网络预赛A题]
题目链接:https://nanti.jisuanke.com/t/30990 Alice, a student of grade 6, is thinking about an Olympian M ...
- 计蒜客 30999.Sum-筛无平方因数的数 (ACM-ICPC 2018 南京赛区网络预赛 J)
J. Sum 26.87% 1000ms 512000K A square-free integer is an integer which is indivisible by any squar ...
- 计蒜客 30996.Lpl and Energy-saving Lamps-线段树(区间满足条件最靠左的值) (ACM-ICPC 2018 南京赛区网络预赛 G)
G. Lpl and Energy-saving Lamps 42.07% 1000ms 65536K During tea-drinking, princess, amongst other t ...
- 【ACM-ICPC 2018 南京赛区网络预赛 A】An Olympian Math Problem
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 估计试几个就会发现答案总是n-1吧. 队友给的证明 [代码] #include <bits/stdc++.h> #def ...
- 计蒜客 1460.Ryuji doesn't want to study-树状数组 or 线段树 (ACM-ICPC 2018 徐州赛区网络预赛 H)
H.Ryuji doesn't want to study 27.34% 1000ms 262144K Ryuji is not a good student, and he doesn't wa ...
- 计蒜客 25985.Goldbach-米勒拉宾素数判定(大素数) (2018 ACM-ICPC 中国大学生程序设计竞赛线上赛 B)
若干年之前的一道题,当时能写出来还是超级开心的,虽然是个板子题.一直忘记写博客,备忘一下. 米勒拉判大素数,关于米勒拉宾是个什么东西,传送门了解一下:biubiubiu~ B. Goldbach 题目 ...
- 【计蒜客】是男人就过 8 题--Pony.AI 题 A. A String Game 后缀自动机+SG函数
[题目]A. A String Game [题意]给定目标串S和n个子串Ti,Alice和Bob轮流选择一个子串操作,必须且只能在子串末尾添加一个字符使得新串也是S的子串,不能操作即输,求胜利者.|S ...
- 计蒜客 31458.Features Track-滚动数组+STL(map)连续计数 (ACM-ICPC 2018 徐州赛区网络预赛 F)
F. Features Track Morgana is learning computer vision, and he likes cats, too. One day he wants to f ...
- 线段树+lazy标记 2019年8月10日计蒜客联盟周赛 C.小A的题
题目链接:https://nanti.jisuanke.com/t/40852 题意:给定一个01串s,进行m次操作,|s|<=1e6,m<=5e5 操作有两种 l r 0,区间[l,r] ...
随机推荐
- BZOJ4477 JSOI2015字符串树(可持久化trie)
树上建可持久化trie即可,有点过于裸了.darkbzoj过了然而在bzoj一直wa,不知道哪有锅. #include<iostream> #include<cstdio> # ...
- [Leetcode] add binary 二进制加法
Given two binary strings, return their sum (also a binary string). For example,a ="11"b =& ...
- ACM模板~求第k短路 ~~~A*+Dijkstra
#include <map> #include <set> #include <cmath> #include <ctime> #include < ...
- ICE学习笔记一----运行官方的java版demo程序
建议新手和我一样,从官网下载英文文档,开个有道词典,慢慢啃. 官方文档下载: http://download.csdn.net/detail/xiong_mao_1/6300631 程序代码就不说了, ...
- 查找算法总结Java实现
之前对查找算法做的一些简单总结与实现: 查找算法时间复杂度: 1.二分查找的实现(待补充) public class Test { //循环实现二分查找 public static int binar ...
- 关押罪犯洛谷P1525
题目+评测传送门 思路 其实这一题有2种不同的思路,但是由于我实在是太蒟蒻了,只会其中一种,另一种看了半天都不知道它在讲什么/(ㄒoㄒ)/~~ 首先,我们要学习一下二分图及其判断方法博客,然后这个题目 ...
- Splunk Power User认证
课程介绍 | 通过 Splunk Fundamentals Part 1 课程考试 | 获取splunk certificate user 证书 | 课程为14节课+课后实验环境+课后习题 | 课程有 ...
- python3 正则表达式re模块
正则表达式的功能:字符串的模糊匹配查询import re元字符 . ---->匹配除换行符意外的任意字符 ^ ---->匹配行首位置 $ ---->匹配行尾位置 关于重复的元字符 * ...
- python3 生成器表达式
生成器表达式 [i for i in range(100)] #列表解析 与列表解析的不同是,列表解析用中括号,生成器表达式用小括号 g = (i for i in range(1000)) #生成器 ...
- [Leetcode Week4]Course Schedule II
Course Schedule II题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/course-schedule-ii/description/ De ...