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 ...
随机推荐
- 动态规划——Valid Permutations for DI Sequence
We are given S, a length n string of characters from the set {'D', 'I'}. (These letters stand for &q ...
- Android SQL数据库应用实践 “问题点”“疑难点”“解析”
应用 Android SQL 数据库时,遇到的问题: 场景1:Android SQL查询后,获取到Cursor并查询数据:遇到以下问题:"android.database.CursorInd ...
- postman基本使用
一.安装 官网:https://www.getpostman.com/ Postman是一个Chrome的一个插件工具,我们可以通过Chrome的应用商店进行进行搜索并安装,安装完成会在桌面上显示一个 ...
- 使用Dubbo的SPI扩展机制实现自定义LoadBalance——方法二 不改源码添加META-INF/dubbo元数据
一.官网提供的方法 参考官网 http://dubbo.apache.org/zh-cn/docs/dev/impls/load-balance.html 二.方法总结 在工程中创建类并实现LoadB ...
- Dynamics 365 解决方案导出报错
之前导出解决方案异常,按照CRM社区的方法解决成功,但是没有了解原因,今天看到有朋友解答了原因,也分享给大家 先来看看异常 我那时导出的是default解决方案,这是模拟 导出异常 “业务流程错误”- ...
- jmeter 入门学习-通过代理录制测试脚本
通过jmeter代理录制脚本后,会产生大量的无用的请求,尽管在代理中已经过滤了一部分图片或者CSS.JS文件. 手动查看主要的请求:这里主要关注登陆请求,要确定有效的URL请求 删除除/Login.a ...
- 正版STLINK使用注意
原文:https://blog.csdn.net/xinghuanmeiying/article/details/78026561 盗版的TVCC是3.3v,可以只用1,7,9,12 正版的TVCC是 ...
- 20175303 2018-2019-2 《Java程序设计》第8周学习总结
20175303 2018-2019-2 <Java程序设计>第8周学习总结 教材学习内容总结 本周学习<Java程序设计>第十五章: 泛型: 泛型(Generics)的主要目 ...
- nginx匹配规则说明以及匹配的优先级
location 匹配规则语法规则 location [=|~|~*|^~] /uri/ { … } 模式 含义location = /uri = 表示精确匹配,只有完全匹配上才能生效lo ...
- NodeJS笔记(五) 使用React Native 创建第一个 Android APP
参考:原文地址 几个月前官方推出了快速创建工具包,由于对React Native不熟悉这里直接使用这2个工具包进行创建 1. create-react-native-app(下文简称CRNA): 2. ...