QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#589750 | #9309. Graph | ccpy | WA | 33ms | 15332kb | C++14 | 1.4kb | 2024-09-25 19:59:48 | 2024-09-25 19:59:49 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define MAX 1000005
using namespace std;
const ll mod=998244353;
ll qm(ll x){
if(x>=mod) x-=mod;
return x;
}
ll fpow(ll a,ll b){
ll r=1;
while(b){
if(b&1) r=r*a%mod;
a=a*a%mod;b>>=1;
}
return r;
}
int pri[MAX],cnt;
bool vis[MAX];
void init(){
int mx=1000000;
for(int i=2;i<=mx;i++){
if(!vis[i]) pri[++cnt]=i;
for(int j=1;j<=cnt&&i*pri[j]<=mx;j++){
vis[i*pri[j]]=1;
if(i%pri[j]==0) break;
}
}
}
ll n,m;
int id1[MAX],id2[MAX],tot;
int id(ll x){
if(x<=m) return id1[x];
return id2[n/x];
}
ll w[MAX];
ll g[MAX];
int main(){
init();
ios::sync_with_stdio(0);
cin.tie(0);
cin>>n;m=sqrt(n);
for(ll l=1,r;l<=n;l=r+1){
w[++tot]=n/l;
r=n/(n/l);
g[tot]=w[tot]-1;
if(w[tot]<=m) id1[w[tot]]=tot;
else id2[n/w[tot]]=tot;
}
for(int i=1;i<=cnt;i++){
for(int j=1;j<=tot&&1ll*pri[i]*pri[i]<=w[j];j++){
int k=id(w[j]/pri[i]);
g[j]-=(g[k]-(i-1));
}
}
ll ans=1;
for(ll l=1,r;l<=n;l=r+1){
int k=id(n/l);
r=n/(n/l);
ll tp=g[id(n/l)]-g[id(n/l/2)]+1;
ll rs=w[k]-tp;
ll sm=1;
if((tp+(rs>0))>1) sm=(rs?rs:1ll)*fpow(w[k],(tp+(rs>0))-2)%mod;
ans=ans*fpow(sm,r-l+1)%mod;
}
cout<<ans;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 5ms
memory: 8972kb
input:
4
output:
8
result:
ok answer is '8'
Test #2:
score: 0
Accepted
time: 2ms
memory: 8912kb
input:
2
output:
1
result:
ok answer is '1'
Test #3:
score: 0
Accepted
time: 5ms
memory: 8912kb
input:
123
output:
671840470
result:
ok answer is '671840470'
Test #4:
score: 0
Accepted
time: 5ms
memory: 11036kb
input:
233
output:
353738465
result:
ok answer is '353738465'
Test #5:
score: 0
Accepted
time: 5ms
memory: 8908kb
input:
5981
output:
970246821
result:
ok answer is '970246821'
Test #6:
score: 0
Accepted
time: 0ms
memory: 9044kb
input:
86422
output:
897815688
result:
ok answer is '897815688'
Test #7:
score: 0
Accepted
time: 2ms
memory: 10816kb
input:
145444
output:
189843901
result:
ok answer is '189843901'
Test #8:
score: 0
Accepted
time: 5ms
memory: 8928kb
input:
901000
output:
819449452
result:
ok answer is '819449452'
Test #9:
score: 0
Accepted
time: 5ms
memory: 9044kb
input:
1000000
output:
113573943
result:
ok answer is '113573943'
Test #10:
score: 0
Accepted
time: 0ms
memory: 9212kb
input:
23333333
output:
949849384
result:
ok answer is '949849384'
Test #11:
score: 0
Accepted
time: 8ms
memory: 9196kb
input:
102850434
output:
604886751
result:
ok answer is '604886751'
Test #12:
score: 0
Accepted
time: 19ms
memory: 13436kb
input:
998244353
output:
0
result:
ok answer is '0'
Test #13:
score: 0
Accepted
time: 20ms
memory: 15332kb
input:
1000000007
output:
318420284
result:
ok answer is '318420284'
Test #14:
score: 0
Accepted
time: 27ms
memory: 9928kb
input:
2147483547
output:
688759898
result:
ok answer is '688759898'
Test #15:
score: -100
Wrong Answer
time: 33ms
memory: 13796kb
input:
5120103302
output:
406301251
result:
wrong answer expected '116870489', found '406301251'