QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#573974#9309. GraphshattershadeAC ✓295ms34632kbC++201.4kb2024-09-18 20:28:482024-09-18 20:28:48

Judging History

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

  • [2024-09-18 20:28:48]
  • 评测
  • 测评结果:AC
  • 用时:295ms
  • 内存:34632kb
  • [2024-09-18 20:28:48]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long 
using namespace std;
const int N=1e6+10;
const int MOD=998244353;

int powM(int a,int b=MOD-2){
	int ans=1;
	a%=MOD;
	while(b){
		if(b&1)ans=ans*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return ans;
}

int p[N],ptot;
bool isp[N];
int lim,n;
void ini(){
	for(int i=2;i<=lim;++i){
		if(!isp[i])p[++ptot]=i;
		for(int j=1;j<=ptot&&p[j]*i<=lim;++j){
			isp[p[j]*i]=true;
			if(i%p[j]==0)break;
		}
	}
}

int idx1[N],idx2[N],val[N],cnt[N];
inline int getid(int x){
	if(x<=lim)return idx1[x];
	return idx2[n/x];
}

int g[N];

void llz(){
	cin>>n;
	lim=min(n,(int)sqrtl(n)+1);
	ini();
	int idxtot=0;
	for(int l=1,r;l<=n;l=r+1){
		r=n/(n/l);
		val[++idxtot]=n/l;
		if(n/l<=lim)idx1[n/l]=idxtot;
		else idx2[l]=idxtot;
		g[idxtot]=n/l-1;
		cnt[idxtot]=r-l+1;
	}
	for(int j=1;j<=ptot;++j){
		for(int i=1;i<=idxtot&&p[j]*p[j]<=val[i];++i){
			g[i]=(g[i]-(g[getid(val[i]/p[j])]-g[getid(p[j-1])]));
		}
	}
	int ans=1;
	for(int i=1;i<idxtot;++i){
		int np=g[i]-g[getid(val[i]/2)];
		int k=np+1;
		if(np+1<val[i])k++;
		int res;
		if(k-2>=0)res=max(val[i]-np-1,1ll)%MOD*powM(val[i],k-2)%MOD;
		else res=1;
		ans=ans*powM(res,cnt[i])%MOD;
	}
	cout<<ans<<"\n";
}

signed main(){
	iostream::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ini();
	int T=1;
	while(T--)llz();
	return 0;
} 

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 11876kb

input:

4

output:

8

result:

ok answer is '8'

Test #2:

score: 0
Accepted
time: 0ms
memory: 9824kb

input:

2

output:

1

result:

ok answer is '1'

Test #3:

score: 0
Accepted
time: 1ms
memory: 11848kb

input:

123

output:

671840470

result:

ok answer is '671840470'

Test #4:

score: 0
Accepted
time: 1ms
memory: 11924kb

input:

233

output:

353738465

result:

ok answer is '353738465'

Test #5:

score: 0
Accepted
time: 1ms
memory: 11876kb

input:

5981

output:

970246821

result:

ok answer is '970246821'

Test #6:

score: 0
Accepted
time: 1ms
memory: 11812kb

input:

86422

output:

897815688

result:

ok answer is '897815688'

Test #7:

score: 0
Accepted
time: 1ms
memory: 11876kb

input:

145444

output:

189843901

result:

ok answer is '189843901'

Test #8:

score: 0
Accepted
time: 1ms
memory: 11820kb

input:

901000

output:

819449452

result:

ok answer is '819449452'

Test #9:

score: 0
Accepted
time: 1ms
memory: 11948kb

input:

1000000

output:

113573943

result:

ok answer is '113573943'

Test #10:

score: 0
Accepted
time: 3ms
memory: 11924kb

input:

23333333

output:

949849384

result:

ok answer is '949849384'

Test #11:

score: 0
Accepted
time: 0ms
memory: 12044kb

input:

102850434

output:

604886751

result:

ok answer is '604886751'

Test #12:

score: 0
Accepted
time: 12ms
memory: 16036kb

input:

998244353

output:

0

result:

ok answer is '0'

Test #13:

score: 0
Accepted
time: 11ms
memory: 14240kb

input:

1000000007

output:

318420284

result:

ok answer is '318420284'

Test #14:

score: 0
Accepted
time: 20ms
memory: 14664kb

input:

2147483547

output:

688759898

result:

ok answer is '688759898'

Test #15:

score: 0
Accepted
time: 38ms
memory: 15240kb

input:

5120103302

output:

116870489

result:

ok answer is '116870489'

Test #16:

score: 0
Accepted
time: 96ms
memory: 22244kb

input:

19834593299

output:

523663743

result:

ok answer is '523663743'

Test #17:

score: 0
Accepted
time: 190ms
memory: 27556kb

input:

52500109238

output:

195086665

result:

ok answer is '195086665'

Test #18:

score: 0
Accepted
time: 250ms
memory: 32128kb

input:

84848352911

output:

107959260

result:

ok answer is '107959260'

Test #19:

score: 0
Accepted
time: 284ms
memory: 31908kb

input:

99824435322

output:

0

result:

ok answer is '0'

Test #20:

score: 0
Accepted
time: 283ms
memory: 34632kb

input:

99999999354

output:

316301711

result:

ok answer is '316301711'

Test #21:

score: 0
Accepted
time: 295ms
memory: 34608kb

input:

100000000000

output:

396843576

result:

ok answer is '396843576'

Extra Test:

score: 0
Extra Test Passed