QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#685570#9515. 无限地狱275307894a100 ✓5332ms187920kbC++143.0kb2024-10-28 20:12:242024-10-28 20:12:25

Judging History

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

  • [2024-10-28 20:12:25]
  • 评测
  • 测评结果:100
  • 用时:5332ms
  • 内存:187920kb
  • [2024-10-28 20:12:24]
  • 提交

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;
	const int M=2e7+5;
	int flag[M],pr[M],mu[M],ph;
	void init(){
		const int m=M-5;
		mu[1]=1;
		for(int i=2;i<=m;i++){
			if(!flag[i]) pr[++ph]=i,mu[i]=-1;
			for(int j=1;j<=ph&&i*pr[j]<=m;j++){
				flag[i*pr[j]]=1;
				if(i%pr[j]==0) break;
				mu[i*pr[j]]=-mu[i];
			}
		}
		for(int i=1;i<=m;i++) mu[i]+=mu[i-1];
		
		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]);
			if(id[i]<=m){f[v]=mu[id[i]];continue;}
			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%=Mod;
		if(x<B) return p1[x];
		return p1[x&(1<<15)-1]*p2[x>>15]%mod;
	}
}

int vis[N];ll f[N],g[N],dp[N];
ll ask(ll x){
	return (Pow::qry(x/2)-1+Pow::qry(x-1>>1)-1-x)%mod;
}
void calc(ll n){
	int v=getid(n);vis[v]=1;
	// gdb(n);
	g[v]=Pow::qry(n)-1;
	for(ll l=2,r;l<=n;l=r+1){
		r=n/(n/l);
		int u=getid(n/l);
		if(!vis[u]) calc(n/l);
		g[v]+=(Mu::f[getid(r)]-Mu::f[getid(l-1)])*(Pow::qry(n/l)-1);
		ll w=ask(r)-ask(l-1);
		(f[v]+=(dp[u]+g[u]-Pow::qry(n/l-1))*(r-l+1)+w*(g[u]*2-1+(f[u]+dp[u])*2))%=mod;
		dp[v]+=(f[u]*2+dp[u]+Pow::qry(n/l-1)-1)*(r-l+1);
		// if(n==5) gdb(f[n]);
	}
	g[v]=(g[v]%mod+mod)%mod;
	f[v]=(f[v]%mod+mod)%mod;
	dp[v]=(f[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';
}

详细

Subtask #1:

score: 4
Accepted

Test #1:

score: 4
Accepted
time: 158ms
memory: 175216kb

input:

6

output:

38

result:

ok 1 number(s): "38"

Test #2:

score: 4
Accepted
time: 168ms
memory: 175300kb

input:

7

output:

73

result:

ok 1 number(s): "73"

Test #3:

score: 4
Accepted
time: 159ms
memory: 174664kb

input:

8

output:

148

result:

ok 1 number(s): "148"

Test #4:

score: 4
Accepted
time: 160ms
memory: 175640kb

input:

9

output:

284

result:

ok 1 number(s): "284"

Test #5:

score: 4
Accepted
time: 170ms
memory: 172656kb

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: 161ms
memory: 174988kb

input:

30

output:

536938322

result:

ok 1 number(s): "536938322"

Test #7:

score: 13
Accepted
time: 159ms
memory: 174992kb

input:

35

output:

210046687

result:

ok 1 number(s): "210046687"

Test #8:

score: 13
Accepted
time: 155ms
memory: 172452kb

input:

38

output:

680532913

result:

ok 1 number(s): "680532913"

Test #9:

score: 13
Accepted
time: 163ms
memory: 175228kb

input:

39

output:

362030079

result:

ok 1 number(s): "362030079"

Test #10:

score: 13
Accepted
time: 159ms
memory: 173968kb

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: 158ms
memory: 175416kb

input:

2000

output:

686289840

result:

ok 1 number(s): "686289840"

Test #12:

score: 17
Accepted
time: 160ms
memory: 172828kb

input:

2500

output:

672176744

result:

ok 1 number(s): "672176744"

Test #13:

score: 17
Accepted
time: 163ms
memory: 175192kb

input:

2998

output:

77001108

result:

ok 1 number(s): "77001108"

Test #14:

score: 17
Accepted
time: 160ms
memory: 174796kb

input:

2999

output:

337824775

result:

ok 1 number(s): "337824775"

Test #15:

score: 17
Accepted
time: 164ms
memory: 175376kb

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: 154ms
memory: 172380kb

input:

100000

output:

809175948

result:

ok 1 number(s): "809175948"

Test #17:

score: 21
Accepted
time: 159ms
memory: 172860kb

input:

200000

output:

425311829

result:

ok 1 number(s): "425311829"

Test #18:

score: 21
Accepted
time: 159ms
memory: 174952kb

input:

500000

output:

302623178

result:

ok 1 number(s): "302623178"

Test #19:

score: 21
Accepted
time: 160ms
memory: 174064kb

input:

900000

output:

683174559

result:

ok 1 number(s): "683174559"

Test #20:

score: 21
Accepted
time: 158ms
memory: 175044kb

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: 235ms
memory: 177300kb

input:

100000000

output:

269652149

result:

ok 1 number(s): "269652149"

Test #22:

score: 22
Accepted
time: 369ms
memory: 177436kb

input:

300000000

output:

421051808

result:

ok 1 number(s): "421051808"

Test #23:

score: 22
Accepted
time: 558ms
memory: 175148kb

input:

700000000

output:

834273337

result:

ok 1 number(s): "834273337"

Test #24:

score: 22
Accepted
time: 678ms
memory: 176396kb

input:

990000000

output:

848544380

result:

ok 1 number(s): "848544380"

Test #25:

score: 22
Accepted
time: 687ms
memory: 175648kb

input:

1000000000

output:

341773916

result:

ok 1 number(s): "341773916"

Subtask #6:

score: 23
Accepted

Dependency #5:

100%
Accepted

Test #26:

score: 23
Accepted
time: 3657ms
memory: 182620kb

input:

12000000000

output:

877921487

result:

ok 1 number(s): "877921487"

Test #27:

score: 23
Accepted
time: 4707ms
memory: 184860kb

input:

17000000000

output:

691116504

result:

ok 1 number(s): "691116504"

Test #28:

score: 23
Accepted
time: 5306ms
memory: 186524kb

input:

19900000000

output:

87007717

result:

ok 1 number(s): "87007717"

Test #29:

score: 23
Accepted
time: 5314ms
memory: 187920kb

input:

19990000000

output:

455948458

result:

ok 1 number(s): "455948458"

Test #30:

score: 23
Accepted
time: 5332ms
memory: 185296kb

input:

20000000000

output:

128153394

result:

ok 1 number(s): "128153394"