QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#641092 | #9309. Graph | tarjen | AC ✓ | 288ms | 31636kb | C++20 | 3.6kb | 2024-10-14 18:27:25 | 2024-10-14 18:27:25 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N=1e6+100;
const int M=1e6+5;
const ll mod=998244353;
ll p[M];
int cnt;
ll getmi(ll x,ll y){
ll ret=1;
x%=mod;
while(y){
if(y&1) ret=ret*x%mod;
x=x*x%mod;
y=y>>1;
}
return ret;
}
const ll inv2=getmi(2,mod-2);
const ll inv4=getmi(4,mod-2);
const ll inv6=getmi(6,mod-2);
bitset<N> v;
void seive()
{
for(int i=2;i<N;++i)
{
if(!v[i])
p[++cnt]=i;
for(int j=1;j<=cnt && i*p[j]<N;++j)
{
v[i*p[j]]=true;
if(i%p[j]==0)
break;
}
}
}
struct min25
{
ll n,sum0[M],sum1[M],sum2[M],sum3[M];
ll w[N<<1],g0[N<<1],g1[N<<1],g2[N<<1],g3[N<<1],G[N<<1];
int id1[N],id2[N],tot,sq;
ll calc(ll j,ll x)//f(p^x)的值
{
return p[j]^x;
}
int getid(ll x)
{
if(x<=sq)
return id1[x];
return id2[n/x];
}
void init(ll nn)
{
for(int i=1;i<=cnt;++i)
{
sum0[i]=(sum0[i-1]+1);
// sum1[i]=(sum1[i-1]+p[i])%mod;
// sum2[i]=(sum2[i-1]+p[i]*p[i]%mod)%mod;
// sum3[i]=(sum3[i-1]+p[i]*p[i]%mod*p[i]%mod)%mod;
}
tot=0;
n=nn;
sq=sqrt(n);
for(ll r,mm,m,l=1;l<=n;l=r+1)
{
r=n/(n/l);
w[tot]=m=mm=n/l;
g0[tot]=(mm-1);
// g1[tot]=mm*(mm+1)%mod*inv2%mod-1;
// g2[tot]=mm*(mm+1)%mod*(2*mm%mod+1)%mod*inv6%mod-1;
// g3[tot]=mm*mm%mod*(mm+1)%mod*(mm+1)%mod*inv4%mod-1;
if(m<=sq)
id1[m]=tot;
else
id2[n/m]=tot;
++tot;
}
for(int i=1;i<=cnt;++i)
{
for(int j=0;j<tot && p[i]*p[i]<=w[j];++j)
{
ll t=getid(w[j]/p[i]);
g0[j]=(g0[j]-(g0[t]-sum0[i-1]));
// g1[j]=(g1[j]-p[i]*(g1[t]-sum1[i-1])%mod)%mod;
// g2[j]=(g2[j]-p[i]*p[i]%mod*(g2[t]-sum2[i-1])%mod)%mod;
// g3[j]=(g3[j]-p[i]*p[i]%mod*p[i]%mod*(g3[t]-sum3[i-1])%mod)%mod;
}
}
// rep(i,0,tot-1) G[i]=((g1[i]-g0[i])%mod+mod)%mod;//所有的K 均为calc(1) g[i]即质数的0次方和
// repd(j,cnt,1)
// rep(i,0,tot-1)
// {
// if((ll)p[j]*p[j]>w[i]) break;
// for(ll k=p[j],c=1; k*p[j]<=w[i]; ++c,k*=p[j],(G[i]+=(p[j]^c))%=mod)
// (G[i]+=(p[j]^c)%mod*(G[getid(w[i]/k)]-(g1[getid(p[j])]-g0[getid(p[j])])%mod+mod)%mod)%=mod;
// }
}
ll get(ll x)
{
return G[getid(x)]+1;
}
ll cal0(ll r)
{
return (g0[getid(r)]);
}
ll cal1(ll r)
{
return (g1[getid(r)])%mod;
}
ll cal2(ll r)
{
return (g2[getid(r)])%mod;
}
ll cal3(ll r)
{
return (g3[getid(r)])%mod;
}
}m2;
ll ksm(ll x,ll k){
ll res=1;
while(k){
if(k&1)res=res*x%mod;
x=x*x%mod;
k/=2;
}
return res;
}
int main()
{
seive();
ll n;cin>>n;
m2.init(n);
ll ans=1;
auto solve = [&](ll n){
ll res=1;
if(n==1)return res;
ll p=m2.cal0(n)-m2.cal0(n/2)+1;
// assert(p>=2);
if(n-p>0)res=ksm(n%mod,p+1-2);
else res=ksm(n%mod,p-2);
if(n-p>0)res=res*((n-p)%mod)%mod;
// cout<<"n="<<n<<" res="<<res<<" p="<<p<<endl;
return res;
};
for(ll l=1,r;l<=n;l=r+1){
r=min(n/(n/l),n);
ll x=n/l;
ans=ans*ksm(solve(x),r-l+1)%mod;
}
cout<<ans;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 6ms
memory: 14612kb
input:
4
output:
8
result:
ok answer is '8'
Test #2:
score: 0
Accepted
time: 6ms
memory: 13024kb
input:
2
output:
1
result:
ok answer is '1'
Test #3:
score: 0
Accepted
time: 6ms
memory: 16596kb
input:
123
output:
671840470
result:
ok answer is '671840470'
Test #4:
score: 0
Accepted
time: 6ms
memory: 13068kb
input:
233
output:
353738465
result:
ok answer is '353738465'
Test #5:
score: 0
Accepted
time: 3ms
memory: 16392kb
input:
5981
output:
970246821
result:
ok answer is '970246821'
Test #6:
score: 0
Accepted
time: 6ms
memory: 14956kb
input:
86422
output:
897815688
result:
ok answer is '897815688'
Test #7:
score: 0
Accepted
time: 6ms
memory: 13132kb
input:
145444
output:
189843901
result:
ok answer is '189843901'
Test #8:
score: 0
Accepted
time: 3ms
memory: 16164kb
input:
901000
output:
819449452
result:
ok answer is '819449452'
Test #9:
score: 0
Accepted
time: 6ms
memory: 14592kb
input:
1000000
output:
113573943
result:
ok answer is '113573943'
Test #10:
score: 0
Accepted
time: 7ms
memory: 13144kb
input:
23333333
output:
949849384
result:
ok answer is '949849384'
Test #11:
score: 0
Accepted
time: 9ms
memory: 16268kb
input:
102850434
output:
604886751
result:
ok answer is '604886751'
Test #12:
score: 0
Accepted
time: 19ms
memory: 15192kb
input:
998244353
output:
0
result:
ok answer is '0'
Test #13:
score: 0
Accepted
time: 20ms
memory: 20272kb
input:
1000000007
output:
318420284
result:
ok answer is '318420284'
Test #14:
score: 0
Accepted
time: 28ms
memory: 15088kb
input:
2147483547
output:
688759898
result:
ok answer is '688759898'
Test #15:
score: 0
Accepted
time: 41ms
memory: 15124kb
input:
5120103302
output:
116870489
result:
ok answer is '116870489'
Test #16:
score: 0
Accepted
time: 102ms
memory: 17168kb
input:
19834593299
output:
523663743
result:
ok answer is '523663743'
Test #17:
score: 0
Accepted
time: 187ms
memory: 23452kb
input:
52500109238
output:
195086665
result:
ok answer is '195086665'
Test #18:
score: 0
Accepted
time: 262ms
memory: 21332kb
input:
84848352911
output:
107959260
result:
ok answer is '107959260'
Test #19:
score: 0
Accepted
time: 285ms
memory: 28592kb
input:
99824435322
output:
0
result:
ok answer is '0'
Test #20:
score: 0
Accepted
time: 288ms
memory: 25552kb
input:
99999999354
output:
316301711
result:
ok answer is '316301711'
Test #21:
score: 0
Accepted
time: 285ms
memory: 31636kb
input:
100000000000
output:
396843576
result:
ok answer is '396843576'
Extra Test:
score: 0
Extra Test Passed