QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#667577 | #9515. 无限地狱 | masterhuang | 55 | 217ms | 27452kb | C++23 | 2.7kb | 2024-10-23 00:19:24 | 2024-10-23 00:19:25 |
Judging History
answer
#include<bits/extc++.h>
#define LL long long
#define fr(x) freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);
using namespace std;
using namespace __gnu_pbds;
const int N=1e6+5,mod=998244353,I2=(mod+1)>>1;
int U,pw[N],pr[N/10],mu[N],MU[N],tot,sq;bool v[N];LL n;
struct node{int f,g,h;}a[N],b[N];
inline int md(int x){return x>=mod?x-mod:x;}
inline void ad(int &x,int y){x=md(x+y);}
inline int ksm(int x,int p){int s=1;for(;p;(p&1)&&(s=1ll*s*x%mod),x=1ll*x*x%mod,p>>=1);return s;}
inline int TO(int x){return x<=sq?x:tot+1-(n/x);}
inline void init(int M)
{
for(int i=2;i<=M;i++)
{
if(!v[i]) pr[++pr[0]]=i,mu[i]=-1;
for(int j=1;j<=pr[0]&&i*pr[j]<=M;j++)
{
v[i*pr[j]]=1;if(i%pr[j]==0) break;
mu[i*pr[j]]=-mu[i];
}
}mu[1]=1;
for(int i=pw[0]=1;i<=M;i++) pw[i]=md(pw[i-1]<<1);a[1].g=1;
for(int i=2;i<=M;i++)
{
a[i].f=md(a[i].f+pw[i/2-1]-1);
a[i].g=md(a[i].g+mod-(2ll*a[i].f+pw[i-1]-2*mu[i])%mod);
a[i].h=md(a[i].h+mod-(2ll*a[i].f+pw[i-1]-mu[i])%mod);
int F=(3ll*(a[i].f+pw[i-2]))%mod;
for(int j=i;j<=M;j+=i)
a[j].g=(a[j].g+2ll*(mu[j/i]+mod)*F)%mod,
a[j].h=(a[j].h+1ll*(mu[j/i]+mod)*F)%mod;
for(int j=i+i;j<=M;j+=i)
a[j].f=(a[j].f+a[i].h+1ll*a[i].g*(pw[j/(i<<1)-1]-1))%mod;
}
for(int i=1;i<=M;i++) ad(a[i].f,a[i-1].f),ad(a[i].g,a[i-1].g),ad(a[i].h,a[i-1].h);
for(int i=2;i<=M;i++) mu[i]+=mu[i-1];
for(int i=1;i<=M;i++) mu[i]=md(mu[i]+mod);
}
int Mu(LL n)
{
if(n<=U) return mu[n];int w=TO(n);
if(MU[w]!=-1) return MU[w];int ans=0;
for(LL i=2,j;i<=n;i=j+1) j=n/(n/i),ans=(ans+(j-i+1)%mod*Mu(n/i))%mod;
return MU[w]=md(mod+1-ans);
}
int S(LL n)
{
if(n<=1) return 0;LL k=n>>1;
if(n&1) return ((pw[TO(n/2)]-k-1)%mod+mod)*2%mod;
int t=1ll*pw[TO(n/2)]*(1+I2)%mod,r=mod-(k+1)%mod;
return (t+2ll*r+1)%mod;
}
node sol(LL n)
{
if(n<=U) return a[n];int w=TO(n);
if(b[w].f!=-1) return b[w];int F=0,G=0,H=0;
for(LL i=2,j;i<=n;i=j+1)
{
j=n/(n/i);
}
return a[w]={F,G,H};
}
int main()
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);cin>>n;
for(LL i=1,j;i<=n;i=j+1) j=n/(n/i),tot++;
for(int i=1;i<=tot;i++) MU[i]=-1,b[i]={-1,-1,-1};
init(U=n);sq=sqrtl(n);pw[0]=1;
for(LL i=1,j,c=tot;i<=n;i=j+1,c--) j=n/(n/i),pw[c]=ksm(2,(n/i)%(mod-1));
// for(int i=1;i<n;i++)
// {
// int s=0;
// for(int j=1;j<=i;j++)
// {
// s=(s+1ll*(mu[j]+mod)*F(i/j))%mod;
// }
// a[i].h=(-2ll*a[i].f-ksm(2,i)+1+s)%mod;
// a[i].h=(mod+a[i].h)%mod;
// a[i].g=(-2ll*a[i].f-ksm(2,i)+1+2ll*s)%mod;
// a[i].g=(mod+a[i].g)%mod;
// for(int j=2;j<=i+1;j++)
// {
// f[i+1]=(f[i+1]+1ll*g[(i+1)/j]*(ksm(2,j/2-1)-1)+h[(i+1)/j])%mod;
// }
// }
cout<<(sol(n).f+ksm(2,(n-1)%(mod-1)))%mod;
return 0;
}
详细
Subtask #1:
score: 4
Accepted
Test #1:
score: 4
Accepted
time: 0ms
memory: 9804kb
input:
6
output:
38
result:
ok 1 number(s): "38"
Test #2:
score: 4
Accepted
time: 0ms
memory: 9796kb
input:
7
output:
73
result:
ok 1 number(s): "73"
Test #3:
score: 4
Accepted
time: 0ms
memory: 9800kb
input:
8
output:
148
result:
ok 1 number(s): "148"
Test #4:
score: 4
Accepted
time: 0ms
memory: 11848kb
input:
9
output:
284
result:
ok 1 number(s): "284"
Test #5:
score: 4
Accepted
time: 0ms
memory: 11852kb
input:
10
output:
565
result:
ok 1 number(s): "565"
Subtask #2:
score: 13
Accepted
Dependency #1:
100%
Accepted
Test #6:
score: 13
Accepted
time: 0ms
memory: 9792kb
input:
30
output:
536938322
result:
ok 1 number(s): "536938322"
Test #7:
score: 13
Accepted
time: 0ms
memory: 11960kb
input:
35
output:
210046687
result:
ok 1 number(s): "210046687"
Test #8:
score: 13
Accepted
time: 0ms
memory: 9776kb
input:
38
output:
680532913
result:
ok 1 number(s): "680532913"
Test #9:
score: 13
Accepted
time: 0ms
memory: 9908kb
input:
39
output:
362030079
result:
ok 1 number(s): "362030079"
Test #10:
score: 13
Accepted
time: 3ms
memory: 9784kb
input:
40
output:
723529503
result:
ok 1 number(s): "723529503"
Subtask #3:
score: 17
Accepted
Dependency #2:
100%
Accepted
Test #11:
score: 17
Accepted
time: 3ms
memory: 9812kb
input:
2000
output:
686289840
result:
ok 1 number(s): "686289840"
Test #12:
score: 17
Accepted
time: 2ms
memory: 9772kb
input:
2500
output:
672176744
result:
ok 1 number(s): "672176744"
Test #13:
score: 17
Accepted
time: 2ms
memory: 9816kb
input:
2998
output:
77001108
result:
ok 1 number(s): "77001108"
Test #14:
score: 17
Accepted
time: 2ms
memory: 9736kb
input:
2999
output:
337824775
result:
ok 1 number(s): "337824775"
Test #15:
score: 17
Accepted
time: 2ms
memory: 11852kb
input:
3000
output:
636156660
result:
ok 1 number(s): "636156660"
Subtask #4:
score: 21
Accepted
Dependency #3:
100%
Accepted
Test #16:
score: 21
Accepted
time: 7ms
memory: 10332kb
input:
100000
output:
809175948
result:
ok 1 number(s): "809175948"
Test #17:
score: 21
Accepted
time: 23ms
memory: 11604kb
input:
200000
output:
425311829
result:
ok 1 number(s): "425311829"
Test #18:
score: 21
Accepted
time: 81ms
memory: 19816kb
input:
500000
output:
302623178
result:
ok 1 number(s): "302623178"
Test #19:
score: 21
Accepted
time: 184ms
memory: 24552kb
input:
900000
output:
683174559
result:
ok 1 number(s): "683174559"
Test #20:
score: 21
Accepted
time: 217ms
memory: 27452kb
input:
1000000
output:
126560600
result:
ok 1 number(s): "126560600"
Subtask #5:
score: 0
Runtime Error
Dependency #4:
100%
Accepted
Test #21:
score: 0
Runtime Error
input:
100000000
output:
result:
Subtask #6:
score: 0
Skipped
Dependency #5:
0%