QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#578593 | #9309. Graph | wildfire032 | AC ✓ | 319ms | 31096kb | C++17 | 3.5kb | 2024-09-20 20:14:48 | 2024-09-20 20:14:48 |
Judging History
answer
#include<bits/stdc++.h>
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define repd(i,l,r) for(int i=l;i>=r;--i)
using namespace std;
typedef long long ll;
#define int 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;
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
seive();
ll n,ans=1;
cin>>n;
m2.init(n);
for(int l=1,r=1;l<=n;l=r+1)
{
r=n/(n/l);
int j=(n/l);
auto cal=[&](int j)
{
if(j<=2) return (ll)1;
if(j==3) return (ll)3;
int gj=m2.cal0(j)-m2.cal0(j/2);
return getmi(j%mod,gj)*((j-1-gj)%mod)%mod;
};
ans=ans*getmi(cal(j),(r-l+1))%mod;
}
cout<<(ans+mod)%mod<<"\n";
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 13188kb
input:
4
output:
8
result:
ok answer is '8'
Test #2:
score: 0
Accepted
time: 3ms
memory: 13172kb
input:
2
output:
1
result:
ok answer is '1'
Test #3:
score: 0
Accepted
time: 7ms
memory: 14784kb
input:
123
output:
671840470
result:
ok answer is '671840470'
Test #4:
score: 0
Accepted
time: 7ms
memory: 15140kb
input:
233
output:
353738465
result:
ok answer is '353738465'
Test #5:
score: 0
Accepted
time: 7ms
memory: 16596kb
input:
5981
output:
970246821
result:
ok answer is '970246821'
Test #6:
score: 0
Accepted
time: 7ms
memory: 13248kb
input:
86422
output:
897815688
result:
ok answer is '897815688'
Test #7:
score: 0
Accepted
time: 3ms
memory: 15116kb
input:
145444
output:
189843901
result:
ok answer is '189843901'
Test #8:
score: 0
Accepted
time: 3ms
memory: 14900kb
input:
901000
output:
819449452
result:
ok answer is '819449452'
Test #9:
score: 0
Accepted
time: 3ms
memory: 13212kb
input:
1000000
output:
113573943
result:
ok answer is '113573943'
Test #10:
score: 0
Accepted
time: 4ms
memory: 13152kb
input:
23333333
output:
949849384
result:
ok answer is '949849384'
Test #11:
score: 0
Accepted
time: 6ms
memory: 13064kb
input:
102850434
output:
604886751
result:
ok answer is '604886751'
Test #12:
score: 0
Accepted
time: 21ms
memory: 14572kb
input:
998244353
output:
0
result:
ok answer is '0'
Test #13:
score: 0
Accepted
time: 14ms
memory: 16684kb
input:
1000000007
output:
318420284
result:
ok answer is '318420284'
Test #14:
score: 0
Accepted
time: 29ms
memory: 14604kb
input:
2147483547
output:
688759898
result:
ok answer is '688759898'
Test #15:
score: 0
Accepted
time: 43ms
memory: 19092kb
input:
5120103302
output:
116870489
result:
ok answer is '116870489'
Test #16:
score: 0
Accepted
time: 103ms
memory: 17348kb
input:
19834593299
output:
523663743
result:
ok answer is '523663743'
Test #17:
score: 0
Accepted
time: 201ms
memory: 25272kb
input:
52500109238
output:
195086665
result:
ok answer is '195086665'
Test #18:
score: 0
Accepted
time: 270ms
memory: 25416kb
input:
84848352911
output:
107959260
result:
ok answer is '107959260'
Test #19:
score: 0
Accepted
time: 306ms
memory: 31096kb
input:
99824435322
output:
0
result:
ok answer is '0'
Test #20:
score: 0
Accepted
time: 303ms
memory: 27456kb
input:
99999999354
output:
316301711
result:
ok answer is '316301711'
Test #21:
score: 0
Accepted
time: 319ms
memory: 27064kb
input:
100000000000
output:
396843576
result:
ok answer is '396843576'
Extra Test:
score: 0
Extra Test Passed