QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#589757 | #9309. Graph | ccpy | AC ✓ | 291ms | 28484kb | C++14 | 1.4kb | 2024-09-25 20:00:51 | 2024-09-25 20:00:51 |
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;
a=a%mod;
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%mod:1ll)*fpow(w[k],(tp+(rs>0))-2)%mod;
ans=ans*fpow(sm,r-l+1)%mod;
}
cout<<ans;
}
这程序好像有点Bug,我给组数据试试?
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 9036kb
input:
4
output:
8
result:
ok answer is '8'
Test #2:
score: 0
Accepted
time: 5ms
memory: 9004kb
input:
2
output:
1
result:
ok answer is '1'
Test #3:
score: 0
Accepted
time: 5ms
memory: 9160kb
input:
123
output:
671840470
result:
ok answer is '671840470'
Test #4:
score: 0
Accepted
time: 2ms
memory: 9100kb
input:
233
output:
353738465
result:
ok answer is '353738465'
Test #5:
score: 0
Accepted
time: 5ms
memory: 9040kb
input:
5981
output:
970246821
result:
ok answer is '970246821'
Test #6:
score: 0
Accepted
time: 5ms
memory: 9056kb
input:
86422
output:
897815688
result:
ok answer is '897815688'
Test #7:
score: 0
Accepted
time: 5ms
memory: 9044kb
input:
145444
output:
189843901
result:
ok answer is '189843901'
Test #8:
score: 0
Accepted
time: 2ms
memory: 8976kb
input:
901000
output:
819449452
result:
ok answer is '819449452'
Test #9:
score: 0
Accepted
time: 5ms
memory: 8992kb
input:
1000000
output:
113573943
result:
ok answer is '113573943'
Test #10:
score: 0
Accepted
time: 6ms
memory: 9104kb
input:
23333333
output:
949849384
result:
ok answer is '949849384'
Test #11:
score: 0
Accepted
time: 0ms
memory: 9300kb
input:
102850434
output:
604886751
result:
ok answer is '604886751'
Test #12:
score: 0
Accepted
time: 15ms
memory: 9584kb
input:
998244353
output:
0
result:
ok answer is '0'
Test #13:
score: 0
Accepted
time: 19ms
memory: 11684kb
input:
1000000007
output:
318420284
result:
ok answer is '318420284'
Test #14:
score: 0
Accepted
time: 24ms
memory: 15256kb
input:
2147483547
output:
688759898
result:
ok answer is '688759898'
Test #15:
score: 0
Accepted
time: 41ms
memory: 13820kb
input:
5120103302
output:
116870489
result:
ok answer is '116870489'
Test #16:
score: 0
Accepted
time: 99ms
memory: 19272kb
input:
19834593299
output:
523663743
result:
ok answer is '523663743'
Test #17:
score: 0
Accepted
time: 192ms
memory: 18852kb
input:
52500109238
output:
195086665
result:
ok answer is '195086665'
Test #18:
score: 0
Accepted
time: 261ms
memory: 25484kb
input:
84848352911
output:
107959260
result:
ok answer is '107959260'
Test #19:
score: 0
Accepted
time: 287ms
memory: 28484kb
input:
99824435322
output:
0
result:
ok answer is '0'
Test #20:
score: 0
Accepted
time: 291ms
memory: 25404kb
input:
99999999354
output:
316301711
result:
ok answer is '316301711'
Test #21:
score: 0
Accepted
time: 291ms
memory: 21176kb
input:
100000000000
output:
396843576
result:
ok answer is '396843576'
Extra Test:
score: 0
Extra Test Passed