QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#432949 | #8761. 另一个计数问题 | qzez | AC ✓ | 1552ms | 19856kb | C++14 | 2.3kb | 2024-06-07 21:10:11 | 2024-06-07 21:10:11 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#include"debug.h"
#else
#define debug(...) void()
#endif
#define all(x) (x).begin(),(x).end()
template<class T>
auto ary(T *a,int l,int r){
return vector<T>{a+l,a+1+r};
}
using ll=long long;
using ull=unsigned ll;
const int N=sqrt(1e11)+5,M=N*2,mod=998244353;
ll n;
struct node{
int x,y;
node(int a=0,int b=0):x(a),y(b){}
};
#ifdef DEBUG
ostream& operator << (ostream &out,node a){
return out<<make_pair(a.x,a.y);
}
#endif
node operator + (const node &a,const node &b){
return node((a.x+b.x)%mod,(a.y+b.y)%mod);
}
node operator - (const node &a,const node &b){
return node((a.x+mod-b.x)%mod,(a.y+mod-b.y)%mod);
}
node operator * (const node &a,const node &b){
return node(1ll*a.x*b.x%mod,1ll*a.y*b.y%mod);
}
int cnt,pri[N],vis[N];
node pre[N];
void init(int n){
fill(vis,vis+1+n,0),cnt=0;
for(int i=2;i<=n;i++){
if(!vis[i])pri[++cnt]=i;
for(int j=1;j<=cnt&&i*pri[j]<=n;j++){
vis[i*pri[j]]=1;
if(i%pri[j]==0)break;
}
}
for(int i=1;i<=cnt;i++){
pre[i]=pre[i-1]+node(pri[i],1ll*pri[i]*pri[i]%mod);
}
}
node f[M];
ll val[M];
int k,id1[N],id2[N];
int getid(ll x){
if(x<=n/x)return id1[x];
else return id2[n/x];
}
int sum1(ll x){
x%=mod;
return x*(x+1)/2%mod;
}
int sum2(ll x){
x%=mod;
return x*(x+1)%mod*(x+x+1)%mod*((mod+1)/6)%mod;
}
node calc(ll n){
::n=n;
if(!n)return node();
init(sqrtl(n)),k=0;
for(ll l=1,r;l<=n;l=r+1){
r=n/(n/l);
ll x=n/l;
if(x<=n/x)val[id1[x]=++k]=x;
else val[id2[n/x]=++k]=x;
}
for(int i=1;i<=k;i++)f[i]=node(sum1(val[i])-1,sum2(val[i])-1);
// debug(ary(val,1,k));
// debug(ary(f,1,k));
// debug(cnt,ary(pri,1,cnt));
for(int i=1;i<=cnt;i++){
node x=node(pri[i],1ll*pri[i]*pri[i]%mod);
for(int j=1;j<=k&&val[j]>=1ll*pri[i]*pri[i];j++){
f[j]=f[j]-x*f[getid(val[j]/pri[i])]+x*pre[i-1];
}
// debug(ary(f,1,k),x,pre[pri[i]-1],pri[i]-1);
}
// debug("calc",n,f[getid(n)]);
return f[getid(n)];
}
int main(){
ll n;
cin>>n;
// debug(n,getid(n));
// debug(f[getid(n)]);
node res=calc(n)-calc(n/2);
int sum=(sum1(n)-1-res.x+mod)%mod;
int ans=(sum2(n)-1-res.y+mod)%mod;
ans=(1ll*sum*sum+mod-ans)%mod*((mod+1)/2)%mod;
cout<<ans<<endl;
return 0;
}
#ifdef DEBUG
#include"debug.hpp"
#endif
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 11064kb
input:
4
output:
8
result:
ok 1 number(s): "8"
Test #2:
score: 0
Accepted
time: 0ms
memory: 11124kb
input:
5
output:
8
result:
ok 1 number(s): "8"
Test #3:
score: 0
Accepted
time: 0ms
memory: 11116kb
input:
6
output:
80
result:
ok 1 number(s): "80"
Test #4:
score: 0
Accepted
time: 0ms
memory: 11112kb
input:
7
output:
80
result:
ok 1 number(s): "80"
Test #5:
score: 0
Accepted
time: 0ms
memory: 11124kb
input:
8
output:
200
result:
ok 1 number(s): "200"
Test #6:
score: 0
Accepted
time: 0ms
memory: 11084kb
input:
9
output:
407
result:
ok 1 number(s): "407"
Test #7:
score: 0
Accepted
time: 0ms
memory: 11064kb
input:
10
output:
937
result:
ok 1 number(s): "937"
Test #8:
score: 0
Accepted
time: 0ms
memory: 11020kb
input:
79
output:
3224298
result:
ok 1 number(s): "3224298"
Test #9:
score: 0
Accepted
time: 3ms
memory: 11060kb
input:
123
output:
21077222
result:
ok 1 number(s): "21077222"
Test #10:
score: 0
Accepted
time: 0ms
memory: 11028kb
input:
158
output:
57411585
result:
ok 1 number(s): "57411585"
Test #11:
score: 0
Accepted
time: 0ms
memory: 11060kb
input:
285
output:
605750829
result:
ok 1 number(s): "605750829"
Test #12:
score: 0
Accepted
time: 3ms
memory: 11016kb
input:
355
output:
509863120
result:
ok 1 number(s): "509863120"
Test #13:
score: 0
Accepted
time: 3ms
memory: 11008kb
input:
484
output:
311440260
result:
ok 1 number(s): "311440260"
Test #14:
score: 0
Accepted
time: 0ms
memory: 11052kb
input:
520
output:
102191845
result:
ok 1 number(s): "102191845"
Test #15:
score: 0
Accepted
time: 0ms
memory: 11060kb
input:
706
output:
300787918
result:
ok 1 number(s): "300787918"
Test #16:
score: 0
Accepted
time: 0ms
memory: 11064kb
input:
747
output:
505062591
result:
ok 1 number(s): "505062591"
Test #17:
score: 0
Accepted
time: 3ms
memory: 11064kb
input:
784
output:
181810798
result:
ok 1 number(s): "181810798"
Test #18:
score: 0
Accepted
time: 3ms
memory: 11028kb
input:
76879
output:
716166793
result:
ok 1 number(s): "716166793"
Test #19:
score: 0
Accepted
time: 3ms
memory: 11032kb
input:
209295
output:
753032272
result:
ok 1 number(s): "753032272"
Test #20:
score: 0
Accepted
time: 0ms
memory: 11036kb
input:
220895
output:
874612082
result:
ok 1 number(s): "874612082"
Test #21:
score: 0
Accepted
time: 3ms
memory: 11020kb
input:
243390
output:
68635874
result:
ok 1 number(s): "68635874"
Test #22:
score: 0
Accepted
time: 0ms
memory: 11036kb
input:
414767
output:
862578797
result:
ok 1 number(s): "862578797"
Test #23:
score: 0
Accepted
time: 0ms
memory: 11036kb
input:
431662
output:
231728766
result:
ok 1 number(s): "231728766"
Test #24:
score: 0
Accepted
time: 0ms
memory: 11068kb
input:
521130
output:
106207351
result:
ok 1 number(s): "106207351"
Test #25:
score: 0
Accepted
time: 0ms
memory: 11140kb
input:
668419
output:
580625063
result:
ok 1 number(s): "580625063"
Test #26:
score: 0
Accepted
time: 0ms
memory: 11044kb
input:
700378
output:
790849562
result:
ok 1 number(s): "790849562"
Test #27:
score: 0
Accepted
time: 0ms
memory: 11032kb
input:
965876
output:
856082142
result:
ok 1 number(s): "856082142"
Test #28:
score: 0
Accepted
time: 62ms
memory: 11988kb
input:
998244350
output:
539142456
result:
ok 1 number(s): "539142456"
Test #29:
score: 0
Accepted
time: 58ms
memory: 11964kb
input:
998244351
output:
730264865
result:
ok 1 number(s): "730264865"
Test #30:
score: 0
Accepted
time: 58ms
memory: 11948kb
input:
998244352
output:
326703895
result:
ok 1 number(s): "326703895"
Test #31:
score: 0
Accepted
time: 58ms
memory: 11900kb
input:
998244353
output:
326703895
result:
ok 1 number(s): "326703895"
Test #32:
score: 0
Accepted
time: 58ms
memory: 11948kb
input:
998244354
output:
730264864
result:
ok 1 number(s): "730264864"
Test #33:
score: 0
Accepted
time: 62ms
memory: 11932kb
input:
998244355
output:
539142451
result:
ok 1 number(s): "539142451"
Test #34:
score: 0
Accepted
time: 58ms
memory: 11900kb
input:
998244356
output:
751581014
result:
ok 1 number(s): "751581014"
Test #35:
score: 0
Accepted
time: 104ms
memory: 12312kb
input:
2165916141
output:
216013547
result:
ok 1 number(s): "216013547"
Test #36:
score: 0
Accepted
time: 143ms
memory: 12616kb
input:
3550627266
output:
318019384
result:
ok 1 number(s): "318019384"
Test #37:
score: 0
Accepted
time: 333ms
memory: 13936kb
input:
11640239920
output:
137498099
result:
ok 1 number(s): "137498099"
Test #38:
score: 0
Accepted
time: 423ms
memory: 14552kb
input:
16191777349
output:
991399721
result:
ok 1 number(s): "991399721"
Test #39:
score: 0
Accepted
time: 674ms
memory: 15936kb
input:
31326230483
output:
99981147
result:
ok 1 number(s): "99981147"
Test #40:
score: 0
Accepted
time: 696ms
memory: 16084kb
input:
32810385543
output:
284259680
result:
ok 1 number(s): "284259680"
Test #41:
score: 0
Accepted
time: 768ms
memory: 16420kb
input:
37368395332
output:
511468046
result:
ok 1 number(s): "511468046"
Test #42:
score: 0
Accepted
time: 810ms
memory: 16504kb
input:
40002331093
output:
282851705
result:
ok 1 number(s): "282851705"
Test #43:
score: 0
Accepted
time: 1354ms
memory: 19096kb
input:
82884464396
output:
767050832
result:
ok 1 number(s): "767050832"
Test #44:
score: 0
Accepted
time: 1513ms
memory: 19728kb
input:
96506992785
output:
31413975
result:
ok 1 number(s): "31413975"
Test #45:
score: 0
Accepted
time: 1536ms
memory: 19856kb
input:
99999999995
output:
456189842
result:
ok 1 number(s): "456189842"
Test #46:
score: 0
Accepted
time: 1537ms
memory: 19680kb
input:
99999999996
output:
516138273
result:
ok 1 number(s): "516138273"
Test #47:
score: 0
Accepted
time: 1531ms
memory: 19800kb
input:
99999999997
output:
136420410
result:
ok 1 number(s): "136420410"
Test #48:
score: 0
Accepted
time: 1552ms
memory: 19856kb
input:
99999999998
output:
841974696
result:
ok 1 number(s): "841974696"
Test #49:
score: 0
Accepted
time: 1545ms
memory: 19756kb
input:
99999999999
output:
164762165
result:
ok 1 number(s): "164762165"
Test #50:
score: 0
Accepted
time: 1536ms
memory: 19756kb
input:
100000000000
output:
627965619
result:
ok 1 number(s): "627965619"