QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#566042#9309. Graphbulijiojiodibuliduo#AC ✓285ms18344kbC++171.8kb2024-09-15 22:55:542024-09-15 22:55:55

Judging History

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

  • [2024-09-15 22:55:55]
  • 评测
  • 测评结果:AC
  • 用时:285ms
  • 内存:18344kb
  • [2024-09-15 22:55:54]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef basic_string<int> BI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}()); 
const ll mod=998244353;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

typedef unsigned long long ull;

const int N=1001000;
ull S,n;
bool pr[N];
int m,p[N],tot,_;
ull h[N],num[N],k;
int getid(ull x) {
	return x<=S?x-1:m-n/x;
}
ull ff(ull n) {
	return 1;
}
ull sumf(ull n) { // return 2..n f[i]
	return n-1;
}

void solve(ull n) {
	S=sqrt(n);
	while (S*S<=n) ++S;
	while (S*S>n) --S;
	m=0;
	rep(i,1,S+1) num[m++]=i;
	per(i,1,S+1) if (n/i>S) num[m++]=n/i;

	// find prime ^k
	rep(i,0,m) h[i]=sumf(num[i]);
	int it=0;
	ull y=0;
	rep(p,2,S+1) if (h[p-1]!=h[p-2]) {
		while (num[it]<(ll)p*p) ++it;
		per(i,it,m) h[i]=h[i]-ff(p)*(h[getid(num[i]/p)]-y);
		y+=ff(p);
	}
	// h = 2..n f[p]
	ll ans=1;
	for (ll l=1;l<=n;l+=1) {
		ll d=n/l,r=n/d;
		ll way=1;
		if (d>=2) {
			ll c=h[getid(d)]-h[getid(d/2)]+1;
			if (d==c) {
				way=powmod(d,d-2);
			} else {
				way=(d-c)%mod*powmod(d,c-1)%mod;
			}
		}
		//printf("!! %lld %lld\n",d,way);
		ans=ans*powmod(way,r-l+1)%mod;
		l=r;
	}
	printf("%lld\n",ans);
}

int main() {
	scanf("%llu",&n);
	int M=700000;
	for (int i=2;i<=M;i++) if (!pr[i]) {
		p[tot++]=i;
		for (int j=i;j<=M;j+=i) pr[j]=1;
	}
	solve(n);
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4

output:

8

result:

ok answer is '8'

Test #2:

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

input:

2

output:

1

result:

ok answer is '1'

Test #3:

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

input:

123

output:

671840470

result:

ok answer is '671840470'

Test #4:

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

input:

233

output:

353738465

result:

ok answer is '353738465'

Test #5:

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

input:

5981

output:

970246821

result:

ok answer is '970246821'

Test #6:

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

input:

86422

output:

897815688

result:

ok answer is '897815688'

Test #7:

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

input:

145444

output:

189843901

result:

ok answer is '189843901'

Test #8:

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

input:

901000

output:

819449452

result:

ok answer is '819449452'

Test #9:

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

input:

1000000

output:

113573943

result:

ok answer is '113573943'

Test #10:

score: 0
Accepted
time: 2ms
memory: 9072kb

input:

23333333

output:

949849384

result:

ok answer is '949849384'

Test #11:

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

input:

102850434

output:

604886751

result:

ok answer is '604886751'

Test #12:

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

input:

998244353

output:

0

result:

ok answer is '0'

Test #13:

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

input:

1000000007

output:

318420284

result:

ok answer is '318420284'

Test #14:

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

input:

2147483547

output:

688759898

result:

ok answer is '688759898'

Test #15:

score: 0
Accepted
time: 42ms
memory: 9768kb

input:

5120103302

output:

116870489

result:

ok answer is '116870489'

Test #16:

score: 0
Accepted
time: 97ms
memory: 11940kb

input:

19834593299

output:

523663743

result:

ok answer is '523663743'

Test #17:

score: 0
Accepted
time: 186ms
memory: 14068kb

input:

52500109238

output:

195086665

result:

ok answer is '195086665'

Test #18:

score: 0
Accepted
time: 251ms
memory: 18008kb

input:

84848352911

output:

107959260

result:

ok answer is '107959260'

Test #19:

score: 0
Accepted
time: 281ms
memory: 16564kb

input:

99824435322

output:

0

result:

ok answer is '0'

Test #20:

score: 0
Accepted
time: 285ms
memory: 18344kb

input:

99999999354

output:

316301711

result:

ok answer is '316301711'

Test #21:

score: 0
Accepted
time: 281ms
memory: 16220kb

input:

100000000000

output:

396843576

result:

ok answer is '396843576'

Extra Test:

score: 0
Extra Test Passed