A. An Olympian Math Problem

  • 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

题目来源

ACM-ICPC 2018 南京赛区网络预赛

题意很好理解。

直接代码

代码:

 //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)的更多相关文章

  1. 计蒜客 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 ...

  2. 计蒜客 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 ...

  3. 计蒜客 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 ...

  4. 【ACM-ICPC 2018 南京赛区网络预赛 A】An Olympian Math Problem

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 估计试几个就会发现答案总是n-1吧. 队友给的证明 [代码] #include <bits/stdc++.h> #def ...

  5. 计蒜客 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 ...

  6. 计蒜客 25985.Goldbach-米勒拉宾素数判定(大素数) (2018 ACM-ICPC 中国大学生程序设计竞赛线上赛 B)

    若干年之前的一道题,当时能写出来还是超级开心的,虽然是个板子题.一直忘记写博客,备忘一下. 米勒拉判大素数,关于米勒拉宾是个什么东西,传送门了解一下:biubiubiu~ B. Goldbach 题目 ...

  7. 【计蒜客】是男人就过 8 题--Pony.AI 题 A. A String Game 后缀自动机+SG函数

    [题目]A. A String Game [题意]给定目标串S和n个子串Ti,Alice和Bob轮流选择一个子串操作,必须且只能在子串末尾添加一个字符使得新串也是S的子串,不能操作即输,求胜利者.|S ...

  8. 计蒜客 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 ...

  9. 线段树+lazy标记 2019年8月10日计蒜客联盟周赛 C.小A的题

    题目链接:https://nanti.jisuanke.com/t/40852 题意:给定一个01串s,进行m次操作,|s|<=1e6,m<=5e5 操作有两种 l r 0,区间[l,r] ...

随机推荐

  1. js & disabled mouse right button menus

    js & disabled mouse right button menus 网页可以屏蔽 F12 https://www.cnblogs.com/Marydon20170307/p/9122 ...

  2. ps学习笔记(二)

    1)选择所有图层: Ctrl+Alt+A2)查找层:ctrl+alt+shift+f,需要在层面板输入查找层名,可自动查找层:3)隔离层:可将选择图层,更改为隔离,只对选择的层编辑:注:图层面板中有一 ...

  3. 【bzoj1061】[NOI2008]志愿者招募 线性规划与费用流

    题目描述 申奥成功后,布布经过不懈努力,终于成为奥组委下属公司人力资源部门的主管.布布刚上任就遇到了一个难题:为即将启动的奥运新项目招募一批短期志愿者.经过估算,这个项目需要N 天才能完成,其中第i ...

  4. 【bzoj1018】[SHOI2008]堵塞的交通traffic 线段树区间合并+STL-set

    题目描述 给出一张2*n的网格图,初始每条边都是不连通的.多次改变一条边的连通性或询问两个点是否连通. 输入 第一行只有一个整数C,表示网格的列数.接下来若干行,每行为一条交通信息,以单独的一行“Ex ...

  5. 【南开OJ2264】节操大师(贪心+二分+并查集/平衡树)

    好久没更新了,今天就随便写一个吧 题目内容 MK和他的小伙伴们(共n人,且保证n为2的正整数幂)想要比试一下谁更有节操,于是他们组织了一场节操淘汰赛.他们的比赛规则简单而暴力:两人的节操正面相撞,碎的 ...

  6. 【题解】洛谷P1975排序

    分块,注意重复的值之间的处理.跟普通分块的操作一样的啦,具体可以参见‘不勤劳的图书管理员’. #include <bits/stdc++.h> using namespace std; # ...

  7. WCF分布式开发步步为赢(14):WCF安全编程--基本概念

    WCF安全机制是个非常复杂的问题,因为涉及的知识点较多,所以今天这个文章,会分析进行WCF安全开发应该了解的哪些知识点.如何查看资料.为了更好地理解WCF安全相关知识,我把WCF安全机制主要知识点整理 ...

  8. 封装安卓的okhttp

    1.封装了get方法,handler更新主线程,回调的onsuccess,onfailure,onerror等方法 2.配置文件 api 'com.android.support:recyclervi ...

  9. c#中数据库字符串的连接几种方式

    ADO.net 中数据库连接方式(微软提供) 微软提供了以下四种数据库连接方式:System.Data.OleDb.OleDbConnectionSystem.Data.SqlClient.SqlCo ...

  10. white-space——处理元素内的空白

      定义和用法 white-space 属性设置如何处理元素内的空白.这个属性声明建立布局过程中如何处理元素中的空白符.值 pre-wrap 和 pre-line 是 CSS 2.1 中新增的. 默认 ...