分段打表大法好!!!

打表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的更多相关文章

  1. HDU 4751 Divide Groups (2013南京网络赛1004题,判断二分图)

    Divide Groups Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  2. HDU 4750 Count The Pairs (2013南京网络赛1003题,并查集)

    Count The Pairs Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others ...

  3. 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 ...

  4. 2018ICPC南京网络赛

    2018ICPC南京网络赛 A. An Olympian Math Problem 题目描述:求\(\sum_{i=1}^{n} i\times i! \%n\) solution \[(n-1) \ ...

  5. 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 ...

  6. 2019 南京网络赛A

    南京网络赛自闭现场 https://nanti.jisuanke.com/t/41298 二维偏序经典题型 二维前缀和!!! #include<bits/stdc++.h> using n ...

  7. 计蒜客 2018南京网络赛 I Skr ( 回文树 )

    题目链接 题意 : 给出一个由数字组成的字符串.然后要你找出其所有本质不同的回文子串.然后将这些回文子串转化为整数后相加.问你最后的结果是多少.答案模 1e9+7 分析 : 应该可以算是回文树挺裸的题 ...

  8. 南京网络赛B-The writing on the wall

    30.43% 2000ms 262144K Feeling hungry, a cute hamster decides to order some take-away food (like frie ...

  9. The writing on the wall 南京网络赛2018B题

    样例输入复制 2 3 3 0 3 3 1 2 2 样例输出复制 Case #1: 36 Case #2: 20 题目来源 ACM-ICPC 2018 南京赛区网络预赛 题意: 就是求图中去掉涂黑的方格 ...

  10. 南京网络赛G-Lpl and Energy【线段树】

    During tea-drinking, princess, amongst other things, asked why has such a good-natured and cute Drag ...

随机推荐

  1. MongoDB和Redis的区别

    1).内存管理机制 a.Redis的数据全部存储在内存当中,会定期写入到磁盘当中,当内存不够用时, 可以选择指定的LRU(最近最少使用算法)的算法删除数据: b.MongoDB数据存在内存,有Linu ...

  2. Tomcat 调优的技巧 (转)

    描述 最近在补充自己的短板,刚好整理到Tomcat调优这块,基本上面试必问,于是就花了点时间去搜集一下tomcat调优都调了些什么,先记录一下调优手段,更多详细的原理和实现以后用到时候再来补充记录,下 ...

  3. Codeforce1196_D_F

    D RGB Substring 题意 给定一个只含RGB三种字符的字符串,问最少修改多少个字符,能使得修改后的字符串存在一个长度为\(k\)的子串是...RGBRGB...这个循环字符串的子串. 分析 ...

  4. doT学习(三)之实战

    案例一: <html> <head> <script id="headertmpl" type="text/x-dot-template&q ...

  5. php打开csv

    <?php $fh=fopen("a.csv","r");//这里我们只是读取数据,所以采用只读打开文件流 $arr=fgetcsv($fh);//这个函 ...

  6. java面试题全集(中)

    这部分主要是与Java Web和Web Service相关的面试题. 96.阐述Servlet和CGI的区别? 答:Servlet与CGI的区别在于Servlet处于服务器进程中,它通过多线程方式运行 ...

  7. phpstorm配置总结

    phpstorm配合laravel框架作为项目开发,需要添加自动提示,减少查看文档的次数,本次使用的是idel-helper插件 在当前项目下 编辑composer.json文件文件,添加如下字符 & ...

  8. (转)linux下weblogic12c集群的安装部署

    本文介绍linux下weblogic12c集群的安装部署,版本12c,其他版本操作会有所不同,但其大体操作基本都是一样的 关于weblogic的集群,在此就不多做介绍了,如果有不了解的朋友可以百度搜索 ...

  9. Codeforces Round #605 (Div. 3) 比赛总结

    比赛情况 2h才刀了A,B,C,D.E题的套路做的少,不过ygt大佬给我讲完思路后赛后2min就AC了这题. 比赛总结 比赛时不用担心"时间短,要做多快",这样会匆匆忙忙,反而会做 ...

  10. 从输入一个URL到页面渲染的流程简介

    首先说明以下是我参考网上答案和自己的思考,给出自己的想法,如果有问题,欢迎大家吐槽从用户在浏览器中输入一个URL,到整个页面渲染,这个过程中究竟发生了什么呢?今天先简单写下整个过程,后面再一点点完善. ...