南京网络赛C
分段打表大法好!!!
打表40min,A题1s
https://nanti.jisuanke.com/t/41300
#include<bits/stdc++.h>
#define int long long
using namespace std;
#define mod 998244353
const int maxn=+;
int P[maxn],phi[maxn],cnt=;
bool f[maxn];
void init()
{
phi[]=;
for(int i=;i<maxn;i++){
if(!f[i]){
P[cnt++]=i;
phi[i]=i-;
}
for(int j=;j<cnt;j++){
if(i*P[j]>maxn)break;
f[i*P[j]]=;
if(i%P[j]==){
phi[i*P[j]]=phi[i]*P[j];
break;
}
phi[i*P[j]]=phi[i]*(P[j]-);
}
}
}
int qp(int x,int n)
{
int ans=;
int a=x;
while(n){
if(n&){
ans=(ans*a)%mod;
}
a=(a*a)%mod;
n>>=;
}
return ans;
}
int ans=;
void cal(int n)
{
int i,j;
int b;
for(j=;j<=n;j++)
for(i=;i<=n;i++){ b=qp(,phi[i]*phi[j]);
//else b=B[b];
ans+=(phi[i]*phi[j])%mod*b%mod;
ans%=mod;
}
cout<<ans<<'\n';
}
void cal2(int x,int y)
{
//cout<<x<<' '<<y<<endl;
int b;
for(int i=;i<=y;i++){
int n=i+x;
for(int j=;j<=n;j++){
b=qp(,phi[n]*phi[j]);
//else b=B[b];
if(j!=n){
b=(b*)%mod;
}
ans+=(phi[n]*phi[j])%mod*b%mod;
ans%=mod;
}
}
cout<<ans<<'\n';
}
int Ans[]={,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,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,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
};
signed main()
{
int T;
int n;
init();
scanf("%lld",&T);
while(T--){
scanf("%lld",&n);
if(n<){
ans=;
cal(n);
}else if(n<){
int x=(n-)/;
ans=Ans[x];
//cout<<ans<<'\n';
int a=*(n/);
int b=n%;
cal2(a,b);
}else if(n<){
int x=(n-)/+(-)/;
ans=Ans[x];
int a=()*(n/);
int b=n%;
cal2(a,b);
}else{
int x=(n-)/+(-)/+(-)/;
ans=Ans[x];
int a=()*(n/);
int b=n%;
cal2(a,b);
}
}
}
打表代码:
#include<bits/stdc++.h>
#define int long long
using namespace std;
#define mod 998244353
const int maxn=+;
int P[maxn],phi[maxn],cnt=,B[*maxn+];
bool f[maxn];
void init()
{
phi[]=;
for(int i=;i<maxn;i++){
if(!f[i]){
P[cnt++]=i;
phi[i]=i-;
}
for(int j=;j<cnt;j++){
if(i*P[j]>maxn)break;
f[i*P[j]]=;
if(i%P[j]==){
phi[i*P[j]]=phi[i]*P[j];
break;
}
phi[i*P[j]]=phi[i]*(P[j]-);
}
}
B[]=;
for(int i=;i<=*maxn;i++){
B[i]=(B[i-]*)%mod;
}
}
int qp(int x,int n)
{
int ans=;
int a=x;
while(n){
if(n&){
ans=(ans*a)%mod;
}
a=(a*a)%mod;
n>>=;
}
return ans;
}
int ans=;
void cal(int n)
{
int i,j=n;
int b;
for(i=;i<=n;i++){
b=phi[i]*phi[j];
if(b>=*maxn){
b=qp(B[phi[i]],phi[j]);
}
else b=B[b];
if(i!=n)
b=(*b)%mod;
ans+=(phi[i]*phi[j])%mod*b%mod;
ans%=mod;
}
cout<<ans<<',';
}
signed main()
{
//cout<<sizeof(Ans)/sizeof(Ans[0]);
init();
freopen("a.txt","w",stdout);
for(int i=;i<=;i++){
cal(i);
} }
南京网络赛C的更多相关文章
- HDU 4751 Divide Groups (2013南京网络赛1004题,判断二分图)
Divide Groups Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- HDU 4750 Count The Pairs (2013南京网络赛1003题,并查集)
Count The Pairs Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others ...
- HDU 4758 Walk Through Squares (2013南京网络赛1011题,AC自动机+DP)
Walk Through Squares Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Oth ...
- 2018ICPC南京网络赛
2018ICPC南京网络赛 A. An Olympian Math Problem 题目描述:求\(\sum_{i=1}^{n} i\times i! \%n\) solution \[(n-1) \ ...
- 2019ICPC南京网络赛A题 The beautiful values of the palace(三维偏序)
2019ICPC南京网络赛A题 The beautiful values of the palace https://nanti.jisuanke.com/t/41298 Here is a squa ...
- 2019 南京网络赛A
南京网络赛自闭现场 https://nanti.jisuanke.com/t/41298 二维偏序经典题型 二维前缀和!!! #include<bits/stdc++.h> using n ...
- 计蒜客 2018南京网络赛 I Skr ( 回文树 )
题目链接 题意 : 给出一个由数字组成的字符串.然后要你找出其所有本质不同的回文子串.然后将这些回文子串转化为整数后相加.问你最后的结果是多少.答案模 1e9+7 分析 : 应该可以算是回文树挺裸的题 ...
- 南京网络赛B-The writing on the wall
30.43% 2000ms 262144K Feeling hungry, a cute hamster decides to order some take-away food (like frie ...
- The writing on the wall 南京网络赛2018B题
样例输入复制 2 3 3 0 3 3 1 2 2 样例输出复制 Case #1: 36 Case #2: 20 题目来源 ACM-ICPC 2018 南京赛区网络预赛 题意: 就是求图中去掉涂黑的方格 ...
- 南京网络赛G-Lpl and Energy【线段树】
During tea-drinking, princess, amongst other things, asked why has such a good-natured and cute Drag ...
随机推荐
- Oracle常用启停命令
一.监听启停 Oracle监听的启动.停止和状态查看 Oracle监听启动: lsnrctl start Oracle监听停止: lsnrctl stop Oracle监听状态 lsnrctl sta ...
- qDebug的用法
qDebug用于在控制台输出调试信息,主要有以下几种用法. 1.类似c++的cout函数 QString str="world"; qDebug()<<"he ...
- 第一次参赛经历:ecfinal总结
刚接到要去参加ec的消息时,还是非常激动的,毕竟第一次参赛就参加如此高水平的编程竞赛(更高水平的比赛就是wf). 教练临时组队,把三个从没在一起打过比赛的三个人组成一队,当时有点担心默契和配合上的问题 ...
- keil格式化项目代码
有时候需要用到一个功能,就先会在网上找到对应的程序,但是百度直接拿来的程序通常不是很规范.想着keil5要是有一个自动格式化代码的功能就好啦,上网一查还真有!需要一些设置如下(keil4与keil5都 ...
- windows 2008 创建域服务器问题 账户密码不符合要求
windows 2008新建域时,本地administrator账户将成域Administrator账户.无法新建域,因为本地administrator账户密码不符合要求.*解决办法:很多人都会想到在 ...
- 杜恩德的新博客,都来看看-duende99
啊啊啊啊 https://home.cnblogs.com/u/duende99/
- mybatis 插入数据返回 -1
通常使用mybatis对数据进行增删改会进行返回值的判断, 返回值不为1时说明该条语句执行失败,不过今天遇到程序报错返回值不为1,去数据库查看却发现插入成功了,后来知道原来是因为mybatis一次对多 ...
- 【MQ】为什么选择RocketMQ?
一.前言 提到mq,可能很多朋友都有多耳闻,很多大公司都在使用这种技术.就小编而言,听说使用mq可以进行秒杀的操作,而且使用十分的方便,效率十分的高.以前小编也做过关于秒杀的技术,就是使用悲观锁对DA ...
- MySQL数据库入门常用基础命令
MySQL数据库入门———常用基础命令 数据——公司的生命线,因此在大多数的互联网公司,都在使用开源的数据库产品,MySQL也因此关注度与使用率非常的高,所以做为运维的屌丝们,掌握它的一些基 ...
- javaSql面试题(10题)
有如下四张表: 学生表Student(stuId,stuName,stuAge,stuSex): 课程表Course(courseId,courseName,teacherId): 成绩表Scores ...