QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#685487#9515. 无限地狱275307894a77 2503ms12528kbC++142.8kb2024-10-28 19:41:292024-10-28 19:41:29

Judging History

你现在查看的是最新测评结果

  • [2024-10-28 19:41:29]
  • 评测
  • 测评结果:77
  • 用时:2503ms
  • 内存:12528kb
  • [2024-10-28 19:41:29]
  • 提交

answer

#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define eb emplace_back
#define all(x) x.begin(),x.end()
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;
const int N=1e6+5,M=N*120+5,K=1000+5,mod=998244353,Mod=mod-1;const db eps=1e-9;const int INF=1e9+7;mt19937 rnd(263082);
#define Tp template<typename T>
#define Ts template<typename T,typename... Ar>
namespace Debug{
	Tp void _debug(char* f,T t){cerr<<f<<'='<<t<<endl;}
	Ts void _debug(char* f,T x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);}
	#ifdef LOCAL
	#define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__)
	#else 
	#define gdb(...) void()
	#endif
}using namespace Debug;
ll mpow(ll x,ll y=mod-2){ll ans=1;while(y) y&1&&(ans=ans*x%mod),y>>=1,x=x*x%mod;return ans;}
ll n,k;
int getid(ll x){
	return x<=k?x:k+n/x;
}
namespace Mu{
	ll f[N];
	ll id[N];int ih;
	void init(){
		for(ll l=1,r;l<=n;l=r+1){
			r=n/(n/l);
			id[++ih]=n/l;
		}
		reverse(id+1,id+ih+1);
		for(int i=1;i<=ih;i++){
			int v=getid(id[i]);
			f[v]=1;
			for(ll l=2,r;l<=id[i];l=r+1){
				r=id[i]/(id[i]/l);
				f[v]-=f[getid(id[i]/l)]*(r-l+1);
			}
		}
	}
}
namespace Pow{
	const int B=(1<<15),N=B+5;
	ll p1[N],p2[N];
	void init(int x){
		for(int i=p1[0]=1;i<=B;i++) p1[i]=p1[i-1]*x%mod;
		for(int i=p2[0]=1;i<=B;i++) p2[i]=p2[i-1]*p1[B]%mod;
	}
	ll qry(ll x){
		x=(x%Mod+Mod)%Mod;
		return p1[x&(1<<15)-1]*p2[x>>15]%mod;
	}
}

int vis[N];ll f[N],g[N],dp[N];
ll ask(ll x){
	ll ans=-x;
	ans+=Pow::qry(x/2)-1;
	ans+=Pow::qry(x-1>>1)-1;
	// for(ll i=2;i<=x;i++) ans+=mpow(2,i/2-1);
	return ans%mod;
}
void calc(ll n){
	int v=getid(n);
	if(vis[v]) return;
	vis[v]=1;
	for(ll l=1,r;l<=n;l=r+1){
		r=n/(n/l);
		g[v]+=(Mu::f[getid(r)]-Mu::f[getid(l-1)])*(Pow::qry(n/l)-1)%mod;
	}
	// gdb(n);
	g[v]=(g[v]%mod+mod)%mod;
	for(ll l=2,r;l<=n;l=r+1){
		r=n/(n/l);
		calc(n/l);int u=getid(n/l);
		ll w=ask(r)-ask(l-1);
		f[v]+=w*(f[u]+f[u]-dp[u])*2%mod;
		f[v]+=w*(g[u]*2-1)%mod;
		f[v]+=(f[u]-dp[u])*(r-l+1)%mod;
		f[v]+=(g[u]-mpow(2,n/l-1))*(r-l+1)%mod;
		dp[v]+=(f[u]*3-dp[u])*(r-l+1)%mod;
		dp[v]+=(Pow::qry(n/l-1)-1)*(r-l+1)%mod;
		// if(n==5) gdb(f[n]);
	}
	f[v]=(f[v]%mod+mod)%mod;
	dp[v]=(dp[v]%mod+mod)%mod;
	// gdb(n,f[n],g[n],dp[n]);
}
void Solve(){
	scanf("%lld",&n);
	k=sqrt(n);
	Mu::init();
	Pow::init(2);
	calc(n);
	printf("%lld\n",(f[getid(n)]+mpow(2,n-1))%mod);
}
int main(){
	int t=1;
	// scanf("%d",&t);
	while(t--) Solve();
	cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 4
Accepted

Test #1:

score: 4
Accepted
time: 2ms
memory: 8680kb

input:

6

output:

38

result:

ok 1 number(s): "38"

Test #2:

score: 4
Accepted
time: 1ms
memory: 6656kb

input:

7

output:

73

result:

ok 1 number(s): "73"

Test #3:

score: 4
Accepted
time: 0ms
memory: 6644kb

input:

8

output:

148

result:

ok 1 number(s): "148"

Test #4:

score: 4
Accepted
time: 1ms
memory: 8500kb

input:

9

output:

284

result:

ok 1 number(s): "284"

Test #5:

score: 4
Accepted
time: 1ms
memory: 6492kb

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: 8420kb

input:

30

output:

536938322

result:

ok 1 number(s): "536938322"

Test #7:

score: 13
Accepted
time: 1ms
memory: 6492kb

input:

35

output:

210046687

result:

ok 1 number(s): "210046687"

Test #8:

score: 13
Accepted
time: 0ms
memory: 6612kb

input:

38

output:

680532913

result:

ok 1 number(s): "680532913"

Test #9:

score: 13
Accepted
time: 1ms
memory: 8444kb

input:

39

output:

362030079

result:

ok 1 number(s): "362030079"

Test #10:

score: 13
Accepted
time: 1ms
memory: 6528kb

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: 2ms
memory: 8636kb

input:

2000

output:

686289840

result:

ok 1 number(s): "686289840"

Test #12:

score: 17
Accepted
time: 1ms
memory: 8096kb

input:

2500

output:

672176744

result:

ok 1 number(s): "672176744"

Test #13:

score: 17
Accepted
time: 0ms
memory: 6592kb

input:

2998

output:

77001108

result:

ok 1 number(s): "77001108"

Test #14:

score: 17
Accepted
time: 1ms
memory: 6396kb

input:

2999

output:

337824775

result:

ok 1 number(s): "337824775"

Test #15:

score: 17
Accepted
time: 1ms
memory: 6488kb

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: 3ms
memory: 6512kb

input:

100000

output:

809175948

result:

ok 1 number(s): "809175948"

Test #17:

score: 21
Accepted
time: 5ms
memory: 6632kb

input:

200000

output:

425311829

result:

ok 1 number(s): "425311829"

Test #18:

score: 21
Accepted
time: 8ms
memory: 6636kb

input:

500000

output:

302623178

result:

ok 1 number(s): "302623178"

Test #19:

score: 21
Accepted
time: 12ms
memory: 6668kb

input:

900000

output:

683174559

result:

ok 1 number(s): "683174559"

Test #20:

score: 21
Accepted
time: 13ms
memory: 6676kb

input:

1000000

output:

126560600

result:

ok 1 number(s): "126560600"

Subtask #5:

score: 22
Accepted

Dependency #4:

100%
Accepted

Test #21:

score: 22
Accepted
time: 422ms
memory: 7352kb

input:

100000000

output:

269652149

result:

ok 1 number(s): "269652149"

Test #22:

score: 22
Accepted
time: 988ms
memory: 7816kb

input:

300000000

output:

421051808

result:

ok 1 number(s): "421051808"

Test #23:

score: 22
Accepted
time: 1894ms
memory: 8252kb

input:

700000000

output:

834273337

result:

ok 1 number(s): "834273337"

Test #24:

score: 22
Accepted
time: 2483ms
memory: 12424kb

input:

990000000

output:

848544380

result:

ok 1 number(s): "848544380"

Test #25:

score: 22
Accepted
time: 2503ms
memory: 12528kb

input:

1000000000

output:

341773916

result:

ok 1 number(s): "341773916"

Subtask #6:

score: 0
Time Limit Exceeded

Dependency #5:

100%
Accepted

Test #26:

score: 0
Time Limit Exceeded

input:

12000000000

output:


result: