ACM-ICPC 2018 南京赛区网络预赛(A, J)
A 签到题
Alice, a student of grade 666, 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!:
k!=1×2×⋯×(k−1)×kk! = 1 \times 2 \times \cdots \times (k - 1) \times kk!=1×2×⋯×(k−1)×k
We denote SSS:
S=1×1!+2×2!+⋯+S = 1 \times 1! + 2 \times 2! + \cdots +S=1×1!+2×2!+⋯+
(n−1)×(n−1)! (n - 1) \times (n-1)!(n−1)×(n−1)!
Then SSS module nnn is ____________
You are given an integer nnn.
You have to calculate SSS modulo nnn.
Input
The first line contains an integer T(T≤1000)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 nnn.
It is guaranteed that 2≤n≤10182 \le n\le 10^{18}2≤n≤1018.
Output
For each test case, print an integer SSS modulo nnn.
Hint
The first test is: S=1×1!=1S = 1\times 1!= 1S=1×1!=1, and 111 modulo 222 is 111.
The second test is: S=1×1!+2×2!=5S = 1\times 1!+2 \times 2!= 5S=1×1!+2×2!=5 , and 555 modulo 333 is 222.
打个表就会发现结果等于 N-1;直接输出就是了;
F
题目链接 :https://nanti.jisuanke.com/t/30999
思路 : 欧筛 + 打表 ,水过的
#include<cstring>
#include<iostream>
#include<cstdio>
#include<ctime>
using namespace std;
#define N 20000005
#define ll long long
int vis[N];
int p[N], cnt, v[N];
ll sum[N];
void init(){
int i, j, k;
sum[]= ;
for(i = ; i < N; ++i){
sum[i] = sum[i-]+vis[i]; // sum[i] 就是答案
if (v[i]== ){
p[cnt++] = i;
}
for (j = ; j < cnt && i * p[j] < N; j++){
ll ans = p[j]*p[j];
if(i%p[j]) {vis[i*p[j]] = vis[i]*; v[i*p[j]] =;}
if(i%ans == ) {vis[i*p[j]] =; v[i*p[j]] =;break;} // 如果i含有至少两个相同的素数, 将 vis[i*p[j]] 置0;
if(i%p[j]==){vis[i*p[j]] = vis[i]/; v[i*p[j]] =;break;}
}
}
} int main()
{
vis[] = ;
for(int i = ; i < N; i++)
{
vis[i] = ;
}
init();
int t;
cin >> t;
while(t--)
{
int n;
cin >> n;
cout << sum[n] << endl;
/* for(int i = 1; i <= 300; i++)
{
cout << "vis " << i <<" : " << vis[i] << endl;
cout << "sum "<< i << " : " << sum[i] << endl; } */ }
}
ACM-ICPC 2018 南京赛区网络预赛(A, J)的更多相关文章
- ACM-ICPC 2018 南京赛区网络预赛 J.sum
A square-free integer is an integer which is indivisible by any square number except 11. For example ...
- ACM-ICPC 2018 南京赛区网络预赛 E题
ACM-ICPC 2018 南京赛区网络预赛 E题 题目链接: https://nanti.jisuanke.com/t/30994 Dlsj is competing in a contest wi ...
- ACM-ICPC 2018 南京赛区网络预赛B
题目链接:https://nanti.jisuanke.com/t/30991 Feeling hungry, a cute hamster decides to order some take-aw ...
- 计蒜客 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 ...
- 计蒜客 30990.An Olympian Math Problem-数学公式题 (ACM-ICPC 2018 南京赛区网络预赛 A)
A. An Olympian Math Problem 54.28% 1000ms 65536K Alice, a student of grade 66, is thinking about a ...
- ACM-ICPC 2018 南京赛区网络预赛 B. The writing on the wall
题目链接:https://nanti.jisuanke.com/t/30991 2000ms 262144K Feeling hungry, a cute hamster decides to o ...
- ACM-ICPC 2018 南京赛区网络预赛
轻轻松松也能拿到区域赛名额,CCPC真的好难 An Olympian Math Problem 问答 只看题面 54.76% 1000ms 65536K Alice, a student of g ...
- ACM-ICPC 2018 南京赛区网络预赛 L. Magical Girl Haze
262144K There are NN cities in the country, and MM directional roads from uu to v(1\le u, v\le n)v ...
- ACM-ICPC 2018 南京赛区网络预赛(12/12)
ACM-ICPC 2018 南京赛区网络预赛 A. An Olympian Math Problem 计算\(\sum_{i=1}^{n-1}i\cdot i!(MOD\ n)\) \(\sum_{i ...
随机推荐
- MyBatis3系列__01HelloWorld
# MyBatis作为一个ORM框架,其重要程度不用过多介绍.下面开始一起学习吧:本博客的编程方法与MyBatis官方文档基本一致:## 1.创建一个数据库mybatis_learn以及对应的表tbl ...
- centos7.4安装npm
下载网址 https://nodejs.org/dist/latest-v8.x/ 安装过程参考 https://blog.csdn.net/micarlxm/article/details/8109 ...
- JS-词法作用域 作用域链
## 词法作用域 概念:所谓的词法作用域,就是代码在编写过程就体现出来的作用范围.代码一旦写好,不用执行, 作用范围就已经确定好了,这个就是所谓的词法作用域. ## 词法作用域的规则: 1,函数允许访 ...
- textarea 中的换行符
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- python语法_str_eval
dict1 = {} a = str(dict1) type(a) = 字符串 b = eval(a) type(b) = 字典
- 技术Leader相关文章和思考
参考文章: 你与优秀的技术Leader之间只差这一个“图谱” 如何成为优秀的技术主管?你要做到这三点
- IAB303 Data Analytics Assessment Task
Assessment TaskIAB303 Data Analyticsfor Business InsightSemester I 2019Assessment 2 – Data Analytics ...
- Logstash - Working with plugins(使用插件)
本章节开始介绍logstash的插件及功能,插件对于logstash来说非常重要,按类别分为:input.filter.codec.output四种类型. logstash有非常丰富的插件,通过安装目 ...
- Hibernate处理事务并发问题
在Hibernate中设置事务的隔离级别.<property name="hibernate.connection.isolation">2</property& ...
- AngularJS简单例子
双大括号标记{{}}绑定的表达式 <html ng-app> <script src="http://code.angularjs.org/angular-1.0.1.mi ...