分段打表大法好!!!

打表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. 2015沈阳区域赛Meeting(最短路 + 建图)

    Meeting Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total ...

  2. Magento开发基础知识之RequireJs

    一.RequireJS概述 RequireJS是一个工具库,主要用于客户端的模块管理.实现异步或动态加载,从而提高代码的性能和可维护性. RequireJS的基本思想是,通过define方法,将代码定 ...

  3. 初识JavaScript(三)

    初识JavaScript(三) 我从上一讲<初识JavaScript(二)>了解到了类型.值.变量的定义以及特点,本节我将学习到JavaScript中的算术运算.二进制浮点数和四舍五入的错 ...

  4. Java Web开发技术教程入门-初识动态网页

    这段时间学校搞了一个"阅战阅勇"的阅读活动,奖品还是挺丰富的~于是,奔着这些奖品,我去图书馆借了这本<Java Web开发技术教程>.一是为了那些丰富的奖品,二是为了回 ...

  5. window下git代码推送

    https://blog.csdn.net/luosaosao/article/details/63684470

  6. 一、Core授权(基于cookie)

    一.Core的授权 配置 打开项目中的Startup.cs文件,找到ConfigureServices方法,我们通常在这个方法里面做依赖注入的相关配置.添加如下代码: public void Conf ...

  7. 四、Signalr手持令牌验证

    一.JWT 服务端在respose中设置好cookie,浏览器发请求都会自动带上,不需要做额外设置 但是如果客户端是非浏览器,或者要兼容多种客户端,这个方法就不行了 Js端 @{ Layout = n ...

  8. heartbeat如何避免脑裂

    heartbeat避免脑裂的方法 1)增加冗余的心跳线,例如双线条线,尽量减少脑裂发生的机会 2)启用磁盘锁:正在服务的一方锁住了共享磁盘,脑裂发生时,让对方完全抢走资源,如果占用资源的一方不解锁 , ...

  9. Tomcat的3种部署方式

    tomcat部署的三种方式及优缺点对比 部署方法一:将编译成功的web项目直接放到webapps目录中(注意是编译成功的web项目,也可以是war包):   部署方式二:修改tomcat安装目录下的  ...

  10. controller 有两种写法,讨论一下两种写法的区别:

    controller 有两种写法,讨论一下两种写法的区别: 写法 1: app.controller('myCtrl', function($scope, $location) { $scope.my ...