计蒜客 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] ...
随机推荐
- NIO--2-代码
package com.study.nio; import java.io.IOException; import java.net.InetSocketAddress; import java.ni ...
- oracle序列使用时 先用伪列将序列的id调整到正确的位置
- Codeforces Round #430 (Div. 2) Vitya and Strange Lesson
D.Vitya and Strange Lesson(字典树) 题意: 给一个长度为\(n\)的非负整数序列,\(m\)次操作,每次先全局异或\(x\),再查询\(mex\) \(1<=n< ...
- [Leetcode] Linked list cycle ii 判断链表是否有环
Given a linked list, return the node where the cycle begins. If there is no cycle, returnnull. Follo ...
- [Noip2004]虫食算 dfs
搜索问题的关键:优秀的搜索策略以及行之有效的减枝 对于这道题我们阶乘搜肯定不行所以我们按位搜,我们对每一位的三个数进行赋值,然后判解. 对于此一类的搜索乘上一个几十的常数来减枝往往要比直接搜要快得多, ...
- 版本7以上IE以文件夹视图方式打开FTP的解决
一.问题的提出 版本7以上IE浏览器打开FTP时只出现列表 二.问题的解决 设置ie浏览器选项即可,以ie9为例,设置步骤如下: 1.启动ie,点击设置按钮,弹出菜单选择internet选项命令: 2 ...
- ng双向数据绑定
http://blog.csdn.net/callmekongkong/article/details/54601585
- 上海GDG活动有感
本周参加了场上海的GDG活动.本次活动的主办方 先介绍一下: GDG Shanghai 上海GDG(Google开发者社区,以前是GTUG, Google技术用户组) ,众所周知,Google的搜索引 ...
- lwIP内存管理机制
lwip的内存管理机制,我们以enet_lwip这个例程为例. 在使用lwip的时候,我们可以使用两种形式的内存,一种是heap(mem.c文件-mem_malloc()),一种是pool(memp. ...
- NetTime
NetTime NetTime is a Simple Network Time Protocol (SNTP) client for Windows 95/98/Me/NT/2000/XP/Vist ...