QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#578160#9309. GraphniolleWA 117ms33696kbC++142.0kb2024-09-20 17:04:302024-09-20 17:04:31

Judging History

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

  • [2024-09-20 17:04:31]
  • 评测
  • 测评结果:WA
  • 用时:117ms
  • 内存:33696kb
  • [2024-09-20 17:04:30]
  • 提交

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) % mod;
		}
		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)%mod;
	}
	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];
			Add(g[j],-(g[k]-sp[i-1])%mod);
		}
	}
}
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;
		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;
		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;
//		cout<<"NOW:"<<k<<" "<<k2<<" "<<p<<" "<<res<<" "<<l<<" "<<r<<" "<<ans<<endl;
		ans = ans * ksm(res,r-l+1) % mod;
	}
}
signed main(){
	shai();
	pre();
	wk();
	cout << ans;
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 4ms
memory: 18820kb

input:

4

output:

8

result:

ok answer is '8'

Test #2:

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

input:

2

output:

1

result:

ok answer is '1'

Test #3:

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

input:

123

output:

671840470

result:

ok answer is '671840470'

Test #4:

score: 0
Accepted
time: 7ms
memory: 22576kb

input:

233

output:

353738465

result:

ok answer is '353738465'

Test #5:

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

input:

5981

output:

970246821

result:

ok answer is '970246821'

Test #6:

score: 0
Accepted
time: 5ms
memory: 20924kb

input:

86422

output:

897815688

result:

ok answer is '897815688'

Test #7:

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

input:

145444

output:

189843901

result:

ok answer is '189843901'

Test #8:

score: 0
Accepted
time: 7ms
memory: 22792kb

input:

901000

output:

819449452

result:

ok answer is '819449452'

Test #9:

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

input:

1000000

output:

113573943

result:

ok answer is '113573943'

Test #10:

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

input:

23333333

output:

949849384

result:

ok answer is '949849384'

Test #11:

score: 0
Accepted
time: 7ms
memory: 25196kb

input:

102850434

output:

604886751

result:

ok answer is '604886751'

Test #12:

score: 0
Accepted
time: 19ms
memory: 29188kb

input:

998244353

output:

0

result:

ok answer is '0'

Test #13:

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

input:

1000000007

output:

318420284

result:

ok answer is '318420284'

Test #14:

score: 0
Accepted
time: 28ms
memory: 27296kb

input:

2147483547

output:

688759898

result:

ok answer is '688759898'

Test #15:

score: 0
Accepted
time: 49ms
memory: 31424kb

input:

5120103302

output:

116870489

result:

ok answer is '116870489'

Test #16:

score: -100
Wrong Answer
time: 117ms
memory: 33696kb

input:

19834593299

output:

-768482857

result:

wrong answer expected '523663743', found '-768482857'