QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#669070 | #9309. Graph | Folity | AC ✓ | 295ms | 29552kb | C++20 | 1.2kb | 2024-10-23 17:11:22 | 2024-10-23 17:11:24 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=5e5+3,mod=998244353;
int cnt=0;
ll pri[N];
bool np[N];
void sieve(int n){
np[1]=1;
for(int i=2;i<=n;++i){
if(!np[i])pri[++cnt]=i;
for(int j=1;j<=cnt&&i*pri[j]<=n;++j){
np[i*pri[j]]=1;
if(!(i%pri[j]))break;
}
}
}
int tot=0;
ll n,q,buc[N*2],g[N*2],i1[N],i2[N];
inline ll S(ll x){
return x<=q?g[i1[x]]:g[i2[n/x]];
}
ll qpow(ll x,ll y){
x%=mod,y%=mod-1;
ll r=1;
for(;y;y>>=1){
if(y&1)r=r*x%mod;
x=x*x%mod;
}
return r;
}
int main(){
cin>>n;
q=sqrt(n);
sieve(q);
for(ll i=1,j;i<=n;i=j+1){
j=n/(n/i);
buc[++tot]=n/i;
g[tot]=buc[tot]-1;
if(n/i<=q)i1[n/i]=tot;
else i2[n/(n/i)]=tot;
}
for(int i=1;i<=cnt;++i)
for(int j=1;j<=tot&&pri[i]*pri[i]<=buc[j];++j){
ll t=buc[j]/pri[i];
ll k=t<=q?i1[t]:i2[n/t];
g[j]-=g[k]-i+1;
}
ll ans=1,w,t;
for(ll i=1,j,m;i<=n/3;i=j+1){
m=n/i,j=n/m;
if(m==3)t=3;
else{
w=S(m)-S(m/2)+2;
t=(m-w+1)%mod*qpow(m,w-2)%mod;
}
ans=ans*qpow(t,j-i+1)%mod;
}
cout<<ans<<'\n';
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 11796kb
input:
4
output:
8
result:
ok answer is '8'
Test #2:
score: 0
Accepted
time: 2ms
memory: 11828kb
input:
2
output:
1
result:
ok answer is '1'
Test #3:
score: 0
Accepted
time: 1ms
memory: 11796kb
input:
123
output:
671840470
result:
ok answer is '671840470'
Test #4:
score: 0
Accepted
time: 0ms
memory: 11852kb
input:
233
output:
353738465
result:
ok answer is '353738465'
Test #5:
score: 0
Accepted
time: 1ms
memory: 11796kb
input:
5981
output:
970246821
result:
ok answer is '970246821'
Test #6:
score: 0
Accepted
time: 0ms
memory: 11860kb
input:
86422
output:
897815688
result:
ok answer is '897815688'
Test #7:
score: 0
Accepted
time: 0ms
memory: 11728kb
input:
145444
output:
189843901
result:
ok answer is '189843901'
Test #8:
score: 0
Accepted
time: 1ms
memory: 11784kb
input:
901000
output:
819449452
result:
ok answer is '819449452'
Test #9:
score: 0
Accepted
time: 0ms
memory: 13732kb
input:
1000000
output:
113573943
result:
ok answer is '113573943'
Test #10:
score: 0
Accepted
time: 0ms
memory: 11812kb
input:
23333333
output:
949849384
result:
ok answer is '949849384'
Test #11:
score: 0
Accepted
time: 5ms
memory: 11984kb
input:
102850434
output:
604886751
result:
ok answer is '604886751'
Test #12:
score: 0
Accepted
time: 11ms
memory: 12152kb
input:
998244353
output:
0
result:
ok answer is '0'
Test #13:
score: 0
Accepted
time: 15ms
memory: 13968kb
input:
1000000007
output:
318420284
result:
ok answer is '318420284'
Test #14:
score: 0
Accepted
time: 20ms
memory: 14128kb
input:
2147483547
output:
688759898
result:
ok answer is '688759898'
Test #15:
score: 0
Accepted
time: 41ms
memory: 14372kb
input:
5120103302
output:
116870489
result:
ok answer is '116870489'
Test #16:
score: 0
Accepted
time: 100ms
memory: 19072kb
input:
19834593299
output:
523663743
result:
ok answer is '523663743'
Test #17:
score: 0
Accepted
time: 189ms
memory: 24136kb
input:
52500109238
output:
195086665
result:
ok answer is '195086665'
Test #18:
score: 0
Accepted
time: 259ms
memory: 24700kb
input:
84848352911
output:
107959260
result:
ok answer is '107959260'
Test #19:
score: 0
Accepted
time: 295ms
memory: 28256kb
input:
99824435322
output:
0
result:
ok answer is '0'
Test #20:
score: 0
Accepted
time: 290ms
memory: 29552kb
input:
99999999354
output:
316301711
result:
ok answer is '316301711'
Test #21:
score: 0
Accepted
time: 295ms
memory: 27452kb
input:
100000000000
output:
396843576
result:
ok answer is '396843576'
Extra Test:
score: 0
Extra Test Passed