QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#448221 | #8761. 另一个计数问题 | 275307894a# | AC ✓ | 1236ms | 25580kb | C++14 | 2.9kb | 2024-06-19 14:30:58 | 2024-06-19 14:30:59 |
Judging History
answer
#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define eb emplace_back
#define all(x) x.begin(),x.end()
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;
const int N=1e6+5,M=5e6+5,K=1000+5,mod=998244353,Mod=mod-1;const db eps=1e-9;const int INF=1e9;mt19937 rnd(time(0));
#define Tp template<typename T>
#define Ts template<typename T,typename... Ar>
namespace Debug{
Tp void _debug(char* f,T t){cerr<<f<<'='<<t<<endl;}
Ts void _debug(char* f,T x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);}
#ifdef LOCAL
#define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__)
#else
#define gdb(...) void()
#endif
}using namespace Debug;
ll n;
ll calc3(ll n){
n%=mod;
return n*(n+1)%mod*(2*n+1)%mod*((mod+1)/6)%mod;
}
ll calc2(ll n){
n%=mod;
return n*(n+1)/2%mod;
}
ll sq(ll x){x%=mod;return x*x%mod;}
int pr[N],flag[N],ph;
ll w[N],sp[N];int wh,i1[N],i2[N];
ll calcp1(ll n){
ph=0;Me(flag,0);
for(int i=2;1ll*i*i<=n;i++){
if(!flag[i]) pr[++ph]=i;
for(int j=1;j<=ph&&1ll*i*i*pr[j]*pr[j]<=n;j++){
flag[i*pr[j]]=1;
if(i%pr[j]==0) break;
}
}
for(int i=1;i<=ph;i++) sp[i]=sp[i-1]+pr[i];
ll x=1;
wh=0;
while(x<=n){
w[++wh]=n/x;
(w[wh]<=n/w[wh]?i1[w[wh]]:i2[n/w[wh]])=wh;
x=n/(n/x)+1;
}
static ll f[N];
for(int i=1;i<=wh;i++) f[i]=calc2(w[i])-1;
auto getid=[&](ll x){
return x<=n/x?i1[x]:i2[n/x];
};
for(int i=1;i<=ph;i++){
for(int j=1;j<=wh&&w[j]>=1ll*pr[i]*pr[i];j++){
f[j]=(f[j]-(f[getid(w[j]/pr[i])]-sp[i-1])%mod*pr[i])%mod;
}
}
return (f[1]%mod+mod-f[2]+mod)%mod;
}
ll calcp2(ll n){
ph=0;Me(flag,0);
for(int i=2;1ll*i*i<=n;i++){
if(!flag[i]) pr[++ph]=i;
for(int j=1;j<=ph&&1ll*i*i*pr[j]*pr[j]<=n;j++){
flag[i*pr[j]]=1;
if(i%pr[j]==0) break;
}
}
for(int i=1;i<=ph;i++) sp[i]=(sp[i-1]+1ll*pr[i]*pr[i])%mod;
ll x=1;
wh=0;
while(x<=n){
w[++wh]=n/x;
(w[wh]<=n/w[wh]?i1[w[wh]]:i2[n/w[wh]])=wh;
x=n/(n/x)+1;
}
static ll f[N];
for(int i=1;i<=wh;i++) f[i]=calc3(w[i])-1;
auto getid=[&](ll x){
return x<=n/x?i1[x]:i2[n/x];
};
for(int i=1;i<=ph;i++){
for(int j=1;j<=wh&&w[j]>=1ll*pr[i]*pr[i];j++){
f[j]=(f[j]-(f[getid(w[j]/pr[i])]-sp[i-1])%mod*pr[i]%mod*pr[i]%mod)%mod;
}
}
return (f[1]%mod+mod-f[2]+mod)%mod;
}
void Solve(){
int i,j;scanf("%lld",&n);
ll ans=sq(calc2(n)-1);
ans-=calc3(n)-1;
ll tot=calcp1(n);
ans+=calcp2(n);
ans-=tot*(calc2(n)-tot-1)*2+tot*tot;
printf("%lld\n",(ans%mod+mod)%mod*(mod+1>>1)%mod);
}
int main(){
int t=1;
// scanf("%d",&t);
while(t--) Solve();
cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 7948kb
input:
4
output:
8
result:
ok 1 number(s): "8"
Test #2:
score: 0
Accepted
time: 0ms
memory: 7956kb
input:
5
output:
8
result:
ok 1 number(s): "8"
Test #3:
score: 0
Accepted
time: 0ms
memory: 7876kb
input:
6
output:
80
result:
ok 1 number(s): "80"
Test #4:
score: 0
Accepted
time: 0ms
memory: 7916kb
input:
7
output:
80
result:
ok 1 number(s): "80"
Test #5:
score: 0
Accepted
time: 0ms
memory: 7972kb
input:
8
output:
200
result:
ok 1 number(s): "200"
Test #6:
score: 0
Accepted
time: 2ms
memory: 7952kb
input:
9
output:
407
result:
ok 1 number(s): "407"
Test #7:
score: 0
Accepted
time: 2ms
memory: 7948kb
input:
10
output:
937
result:
ok 1 number(s): "937"
Test #8:
score: 0
Accepted
time: 3ms
memory: 7860kb
input:
79
output:
3224298
result:
ok 1 number(s): "3224298"
Test #9:
score: 0
Accepted
time: 2ms
memory: 7800kb
input:
123
output:
21077222
result:
ok 1 number(s): "21077222"
Test #10:
score: 0
Accepted
time: 0ms
memory: 7856kb
input:
158
output:
57411585
result:
ok 1 number(s): "57411585"
Test #11:
score: 0
Accepted
time: 0ms
memory: 7932kb
input:
285
output:
605750829
result:
ok 1 number(s): "605750829"
Test #12:
score: 0
Accepted
time: 0ms
memory: 7864kb
input:
355
output:
509863120
result:
ok 1 number(s): "509863120"
Test #13:
score: 0
Accepted
time: 2ms
memory: 7916kb
input:
484
output:
311440260
result:
ok 1 number(s): "311440260"
Test #14:
score: 0
Accepted
time: 0ms
memory: 7964kb
input:
520
output:
102191845
result:
ok 1 number(s): "102191845"
Test #15:
score: 0
Accepted
time: 2ms
memory: 7956kb
input:
706
output:
300787918
result:
ok 1 number(s): "300787918"
Test #16:
score: 0
Accepted
time: 0ms
memory: 7912kb
input:
747
output:
505062591
result:
ok 1 number(s): "505062591"
Test #17:
score: 0
Accepted
time: 2ms
memory: 7964kb
input:
784
output:
181810798
result:
ok 1 number(s): "181810798"
Test #18:
score: 0
Accepted
time: 2ms
memory: 7968kb
input:
76879
output:
716166793
result:
ok 1 number(s): "716166793"
Test #19:
score: 0
Accepted
time: 2ms
memory: 7844kb
input:
209295
output:
753032272
result:
ok 1 number(s): "753032272"
Test #20:
score: 0
Accepted
time: 2ms
memory: 8036kb
input:
220895
output:
874612082
result:
ok 1 number(s): "874612082"
Test #21:
score: 0
Accepted
time: 0ms
memory: 7884kb
input:
243390
output:
68635874
result:
ok 1 number(s): "68635874"
Test #22:
score: 0
Accepted
time: 0ms
memory: 8004kb
input:
414767
output:
862578797
result:
ok 1 number(s): "862578797"
Test #23:
score: 0
Accepted
time: 3ms
memory: 8004kb
input:
431662
output:
231728766
result:
ok 1 number(s): "231728766"
Test #24:
score: 0
Accepted
time: 3ms
memory: 7988kb
input:
521130
output:
106207351
result:
ok 1 number(s): "106207351"
Test #25:
score: 0
Accepted
time: 0ms
memory: 7988kb
input:
668419
output:
580625063
result:
ok 1 number(s): "580625063"
Test #26:
score: 0
Accepted
time: 0ms
memory: 7992kb
input:
700378
output:
790849562
result:
ok 1 number(s): "790849562"
Test #27:
score: 0
Accepted
time: 3ms
memory: 7968kb
input:
965876
output:
856082142
result:
ok 1 number(s): "856082142"
Test #28:
score: 0
Accepted
time: 50ms
memory: 9720kb
input:
998244350
output:
539142456
result:
ok 1 number(s): "539142456"
Test #29:
score: 0
Accepted
time: 45ms
memory: 9620kb
input:
998244351
output:
730264865
result:
ok 1 number(s): "730264865"
Test #30:
score: 0
Accepted
time: 50ms
memory: 9728kb
input:
998244352
output:
326703895
result:
ok 1 number(s): "326703895"
Test #31:
score: 0
Accepted
time: 45ms
memory: 9712kb
input:
998244353
output:
326703895
result:
ok 1 number(s): "326703895"
Test #32:
score: 0
Accepted
time: 50ms
memory: 9576kb
input:
998244354
output:
730264864
result:
ok 1 number(s): "730264864"
Test #33:
score: 0
Accepted
time: 49ms
memory: 9716kb
input:
998244355
output:
539142451
result:
ok 1 number(s): "539142451"
Test #34:
score: 0
Accepted
time: 46ms
memory: 9712kb
input:
998244356
output:
751581014
result:
ok 1 number(s): "751581014"
Test #35:
score: 0
Accepted
time: 79ms
memory: 10536kb
input:
2165916141
output:
216013547
result:
ok 1 number(s): "216013547"
Test #36:
score: 0
Accepted
time: 113ms
memory: 11332kb
input:
3550627266
output:
318019384
result:
ok 1 number(s): "318019384"
Test #37:
score: 0
Accepted
time: 264ms
memory: 13972kb
input:
11640239920
output:
137498099
result:
ok 1 number(s): "137498099"
Test #38:
score: 0
Accepted
time: 333ms
memory: 14956kb
input:
16191777349
output:
991399721
result:
ok 1 number(s): "991399721"
Test #39:
score: 0
Accepted
time: 540ms
memory: 17676kb
input:
31326230483
output:
99981147
result:
ok 1 number(s): "99981147"
Test #40:
score: 0
Accepted
time: 556ms
memory: 18028kb
input:
32810385543
output:
284259680
result:
ok 1 number(s): "284259680"
Test #41:
score: 0
Accepted
time: 616ms
memory: 18588kb
input:
37368395332
output:
511468046
result:
ok 1 number(s): "511468046"
Test #42:
score: 0
Accepted
time: 635ms
memory: 18960kb
input:
40002331093
output:
282851705
result:
ok 1 number(s): "282851705"
Test #43:
score: 0
Accepted
time: 1069ms
memory: 23944kb
input:
82884464396
output:
767050832
result:
ok 1 number(s): "767050832"
Test #44:
score: 0
Accepted
time: 1203ms
memory: 25208kb
input:
96506992785
output:
31413975
result:
ok 1 number(s): "31413975"
Test #45:
score: 0
Accepted
time: 1236ms
memory: 25568kb
input:
99999999995
output:
456189842
result:
ok 1 number(s): "456189842"
Test #46:
score: 0
Accepted
time: 1228ms
memory: 25420kb
input:
99999999996
output:
516138273
result:
ok 1 number(s): "516138273"
Test #47:
score: 0
Accepted
time: 1224ms
memory: 25544kb
input:
99999999997
output:
136420410
result:
ok 1 number(s): "136420410"
Test #48:
score: 0
Accepted
time: 1221ms
memory: 25528kb
input:
99999999998
output:
841974696
result:
ok 1 number(s): "841974696"
Test #49:
score: 0
Accepted
time: 1223ms
memory: 25580kb
input:
99999999999
output:
164762165
result:
ok 1 number(s): "164762165"
Test #50:
score: 0
Accepted
time: 1230ms
memory: 25544kb
input:
100000000000
output:
627965619
result:
ok 1 number(s): "627965619"