QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#578181#9309. GraphniolleAC ✓312ms38268kbC++142.1kb2024-09-20 17:12:212024-09-20 17:12:22

Judging History

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

  • [2024-09-20 17:12:22]
  • 评测
  • 测评结果:AC
  • 用时:312ms
  • 内存:38268kb
  • [2024-09-20 17:12:21]
  • 提交

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

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

详细

Test #1:

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

input:

4

output:

8

result:

ok answer is '8'

Test #2:

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

input:

2

output:

1

result:

ok answer is '1'

Test #3:

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

input:

123

output:

671840470

result:

ok answer is '671840470'

Test #4:

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

input:

233

output:

353738465

result:

ok answer is '353738465'

Test #5:

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

input:

5981

output:

970246821

result:

ok answer is '970246821'

Test #6:

score: 0
Accepted
time: 9ms
memory: 18884kb

input:

86422

output:

897815688

result:

ok answer is '897815688'

Test #7:

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

input:

145444

output:

189843901

result:

ok answer is '189843901'

Test #8:

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

input:

901000

output:

819449452

result:

ok answer is '819449452'

Test #9:

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

input:

1000000

output:

113573943

result:

ok answer is '113573943'

Test #10:

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

input:

23333333

output:

949849384

result:

ok answer is '949849384'

Test #11:

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

input:

102850434

output:

604886751

result:

ok answer is '604886751'

Test #12:

score: 0
Accepted
time: 21ms
memory: 28468kb

input:

998244353

output:

0

result:

ok answer is '0'

Test #13:

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

input:

1000000007

output:

318420284

result:

ok answer is '318420284'

Test #14:

score: 0
Accepted
time: 27ms
memory: 31084kb

input:

2147483547

output:

688759898

result:

ok answer is '688759898'

Test #15:

score: 0
Accepted
time: 43ms
memory: 27972kb

input:

5120103302

output:

116870489

result:

ok answer is '116870489'

Test #16:

score: 0
Accepted
time: 100ms
memory: 33576kb

input:

19834593299

output:

523663743

result:

ok answer is '523663743'

Test #17:

score: 0
Accepted
time: 194ms
memory: 37884kb

input:

52500109238

output:

195086665

result:

ok answer is '195086665'

Test #18:

score: 0
Accepted
time: 272ms
memory: 38268kb

input:

84848352911

output:

107959260

result:

ok answer is '107959260'

Test #19:

score: 0
Accepted
time: 312ms
memory: 36148kb

input:

99824435322

output:

0

result:

ok answer is '0'

Test #20:

score: 0
Accepted
time: 303ms
memory: 38136kb

input:

99999999354

output:

316301711

result:

ok answer is '316301711'

Test #21:

score: 0
Accepted
time: 306ms
memory: 38200kb

input:

100000000000

output:

396843576

result:

ok answer is '396843576'

Extra Test:

score: 0
Extra Test Passed