QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#578171#9309. GraphniolleWA 185ms36052kbC++142.0kb2024-09-20 17:09:162024-09-20 17:09:16

Judging History

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

  • [2024-09-20 17:09:16]
  • 评测
  • 测评结果:WA
  • 用时:185ms
  • 内存:36052kb
  • [2024-09-20 17:09:16]
  • 提交

answer

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define dwn(i,a,b) for(int i=a;i>=b;i--)
#define lowbit(x) (x&(-x))
#define MAXN 1002501
#define N 1000000
#define int long long
#define mp(x,y) make_pair(x,y)
using namespace std;
typedef long long ll;
inline int read(){
	int x=0,f=1;
	char ch=getchar();
	while(ch>'9' || ch<'0'){if(ch=='-') f=-1; ch=getchar();}
	while('0'<=ch && ch<='9') x=(x<<1)+(x<<3)+ch-'0',ch=getchar();
	return x*f;
}
const int mod = 998244353;
int pri[MAXN],cnt,bk[MAXN],id1[MAXN],id2[MAXN],n;
int w[MAXN],tot,g[MAXN],sp[MAXN],ans;
void Add(int &x,int y){
	x += y;
	if(x >= mod) x -= mod;
	if(x < 0) x += mod;
}
int ksm(int x,int y){
	x %= mod;
	int res = 1;
	while(y){
		if(y&1) res = res * x % mod;
		x =  x * x % mod;
		y>>=1;
	}
	return res;
}
void shai(){
	rep(i,2,N){
		if(!bk[i]){
			bk[i] = i;
			pri[++cnt] = i;
			sp[cnt] = (sp[cnt-1] + 1);
		}
		rep(j,1,cnt){
			if(i * pri[j] > N || bk[i] < pri[j]) break;
			bk[i*pri[j]] = pri[j];
		}
	}
}
void pre(){
	n = read();
	for(int l = 1,r; l <= n; l = r + 1){
		r = n/(n/l);
		ll k = n/l;
		w[++tot] = k;
		if(k <= N) id1[k] = tot;
		else id2[n/k] = tot;
		g[tot] = (k-1);
	}
	int l,k;
	rep(i,1,cnt){
		rep(j,1,tot){
			if(w[j] < pri[i] * pri[i]) break;
			l = w[j] / pri[i];
			if(l <= N) k = id1[l];
			else k = id2[n/l];
			g[j] -= (g[k]-sp[i-1]);
		}
	}
}
void wk(){
	int k,j,k2,i,p;
	ll res;
	ans = 1;
	for(int l = 1,r; l <= n; l = r + 1){
		r = n / (n/l);
		k = n / l;
//		cout<<"L:"<<l<<" "<<r<<" "<<k<<endl;
		if(k <= N) j = id1[k];
		else j = id2[n/k];
		k2 = k / 2;
		if(k2 <= N) i = id1[k2];
		else i = id2[n/k2];
		p = (g[j] - g[i] + 2 + mod) % mod;
		if(p > k) p = k;
		if(p == 1) res = 1;
		else if(p == k) res = ksm(k,k-2);
		else if(p == 2) res = k-1;
		else res = ksm(k,p-2) * ((k-p+1)%mod) % mod;
//		cout<<"OK:"<<res<<endl;
		res %= mod;
		ans = ans * ksm(res,r-l+1) % mod;
	}
}
signed main(){
	shai();
	pre();
	wk();
	cout << ans;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 7ms
memory: 18720kb

input:

4

output:

8

result:

ok answer is '8'

Test #2:

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

input:

2

output:

1

result:

ok answer is '1'

Test #3:

score: 0
Accepted
time: 6ms
memory: 18820kb

input:

123

output:

671840470

result:

ok answer is '671840470'

Test #4:

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

input:

233

output:

353738465

result:

ok answer is '353738465'

Test #5:

score: 0
Accepted
time: 6ms
memory: 18796kb

input:

5981

output:

970246821

result:

ok answer is '970246821'

Test #6:

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

input:

86422

output:

897815688

result:

ok answer is '897815688'

Test #7:

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

input:

145444

output:

189843901

result:

ok answer is '189843901'

Test #8:

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

input:

901000

output:

819449452

result:

ok answer is '819449452'

Test #9:

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

input:

1000000

output:

113573943

result:

ok answer is '113573943'

Test #10:

score: 0
Accepted
time: 8ms
memory: 25040kb

input:

23333333

output:

949849384

result:

ok answer is '949849384'

Test #11:

score: 0
Accepted
time: 10ms
memory: 26724kb

input:

102850434

output:

604886751

result:

ok answer is '604886751'

Test #12:

score: 0
Accepted
time: 16ms
memory: 26264kb

input:

998244353

output:

0

result:

ok answer is '0'

Test #13:

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

input:

1000000007

output:

318420284

result:

ok answer is '318420284'

Test #14:

score: 0
Accepted
time: 26ms
memory: 27304kb

input:

2147483547

output:

688759898

result:

ok answer is '688759898'

Test #15:

score: 0
Accepted
time: 47ms
memory: 27392kb

input:

5120103302

output:

116870489

result:

ok answer is '116870489'

Test #16:

score: 0
Accepted
time: 103ms
memory: 29972kb

input:

19834593299

output:

523663743

result:

ok answer is '523663743'

Test #17:

score: -100
Wrong Answer
time: 185ms
memory: 36052kb

input:

52500109238

output:

78396536

result:

wrong answer expected '195086665', found '78396536'