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 ...
随机推荐
- CSS(三)
CSS盒子模型 盒子模型解释 元素在页面中显示成一个方块,类似一个盒子,CSS盒子模型就是使用现实中盒子来做比喻,帮助我们设置元素对应的样式.盒子模型示意图如下: 把元素叫做盒子,设置对应的样式分别为 ...
- idea创建第一个普通java web项目
1.新建项目(工作空间) 选择空项目 输入项目名称,点击完成 系统会默认选中Modules,点击上面的小+号创建模块->New Module 新建一个Java EE Web Applicatio ...
- python语法_深浅拷贝
浅拷贝,.copy 只拷贝第一层(可用于建立银行共享账号). s1 = [‘a’,'b','c'] s2 = s1.copy() s2[0]='d' print(s2) print(s1) 此时修改s ...
- 保护模式.vbs
Sub Main Dim cnt Dim delay delay = 10000 For cnt = 0 To 80 crt.screen.Send "interface optical-r ...
- ubuntu下安装PyCharm的两种方式
PyCharm一个是Python集成开发环境,它既提供收费的专业版,也提供免费的社区版本.PyCharm带有一整套可以帮助用户在使用Python语言开发时提高其效率的工具,比如调试.语法高亮.Proj ...
- 工作流JBPM
jbpm3 共分为12种节点 1.node节点:如果该节点没有定义ACTION,则流转到该节点时不会停留,会继续往下走,如果定义ACTION,执行完ACTION后会停在该节点上,调用 token.si ...
- Jmeter-----参数配置
参数化配置: 设置为3个线程后,三个用户均能运行
- [Day20]Map接口、可变参数、Collections
1.Map接口-元素成对存在,每个元素由健与值两部分组成,通过键可以找所对应的值 1.1 Map子类 (1)HashMap<K,V>:存储数据所用的哈希表结构,元素的存取数据顺序不能保证一 ...
- LeetCode 653 Two Sum IV - Input is a BST 解题报告
题目要求 Given a Binary Search Tree and a target number, return true if there exist two elements in the ...
- linux自定义开机自启多个服务的脚本
linux服务器重启后,每次要启动redis.ftp.tomcat等应用总是很麻烦,于是写了一个自定义脚本,在开机或重启的时候,自动启动多个服务.应用. 很简单,写脚本.设置开机启动. 第一步.准 ...