QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#569959#9309. GraphjeffqiAC ✓461ms29436kbC++172.5kb2024-09-17 12:50:382024-09-17 12:50:38

Judging History

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

  • [2024-09-17 12:50:38]
  • 评测
  • 测评结果:AC
  • 用时:461ms
  • 内存:29436kb
  • [2024-09-17 12:50:38]
  • 提交

answer

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#define ll long long
#define all(v) v.begin(),v.end()
#define sz(v) ((ll)v.size())
#define V vector
#define vi V<int>
#define vll V<ll>
#define eb emplace_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define A array
#define pb push_back
#define mset multiset
#define gpumap __gnu_pbds::gp_hash_table
#define ccumap __gnu_pbds::cc_hash_table
#define ui unsigned int
#define ull unsigned ll
#define i128 __int128
#define cerr if (test) cerr
#define freopen if (test) freopen
#define whtest if (test)
using namespace std;

const int test = 0;

namespace jhsy {
	constexpr int P = 998244353,N = 1e6;
	vi p;
	void init(const int n = N) {
		A<bool,N+1> isp; isp.fill(1);
		for (int i = 2; i <= n; i++) {
			if (isp[i]) {
				p.eb(i);
			}
			for (auto x:p) {
				if (i*x > n) {
					break;
				}
				isp[i*x] = 0;
				if (!(i%x)) {
					break;
				}
			}
		}
	}
	ll power(ll b,ll k) {
		ll a = 1;
		b = (b%P+P)%P;
		k = (k%(P-1)+(P-1))%(P-1);
		for (; k; b = b*b%P, k >>= 1) {
			if (k&1) {
				a = a*b%P;
			}
		}
		return a;
	}
	void main() {
		ll n;
		cin >> n;
		ll ans = 1;
		const ll B = sqrt(1.L*n);
		A<ll,N*2> mp;
		auto id = [&](ll x) {
			return x <= B ? x : B+n/x;
		};
		{
			vll vec;
			for (ll lst = 0,cur; lst < n; lst = cur) {
				ll k = n/(lst+1); cur = n/k;
				vec.eb(cur);
			}
			reverse(all(vec));
			for (auto x:vec) {
				mp[id(x)] = x-1;
			}
			for (int k = 0; k < sz(p); k++) {
				ll t = 1ll*p[k]*p[k];
				if (t > n) {
					break;
				}
				for (auto x:vec) {
					if (t > x) {
						break;
					}
					mp[id(x)] -= mp[id(x/p[k])]-k;
				}
			}
		}
		auto get = [&](ll x) {
			ll res = mp[id(x)]-mp[id(x/2)];
			if (x/2 < 2 && x >= 2) {
				res--;
			}
			return res;
		};
		auto calc = [&](ll x) -> ll {
			if (x == 1) {
				return 1;
			}
			ll p = get(x)+1,q = x-p;
			return q%P*power(p+q,p-1)%P;
		};
		for (ll lst = 0,cur; lst < n; lst = cur) {
			ll k = n/(lst+1); cur = n/k;
			ans = ans*power(calc(k),cur-lst)%P;
		}
		cout << ans << '\n';
	}
}

int main() {
	freopen("test.in", "r", stdin);
	freopen("test.out", "w", stdout);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(20);

	jhsy::init();

	int T = 1;
//	cin >> T;
	while (T--) {
		jhsy::main();
	}

	return 0;
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4

output:

8

result:

ok answer is '8'

Test #2:

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

input:

2

output:

1

result:

ok answer is '1'

Test #3:

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

input:

123

output:

671840470

result:

ok answer is '671840470'

Test #4:

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

input:

233

output:

353738465

result:

ok answer is '353738465'

Test #5:

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

input:

5981

output:

970246821

result:

ok answer is '970246821'

Test #6:

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

input:

86422

output:

897815688

result:

ok answer is '897815688'

Test #7:

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

input:

145444

output:

189843901

result:

ok answer is '189843901'

Test #8:

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

input:

901000

output:

819449452

result:

ok answer is '819449452'

Test #9:

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

input:

1000000

output:

113573943

result:

ok answer is '113573943'

Test #10:

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

input:

23333333

output:

949849384

result:

ok answer is '949849384'

Test #11:

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

input:

102850434

output:

604886751

result:

ok answer is '604886751'

Test #12:

score: 0
Accepted
time: 22ms
memory: 19956kb

input:

998244353

output:

0

result:

ok answer is '0'

Test #13:

score: 0
Accepted
time: 25ms
memory: 19876kb

input:

1000000007

output:

318420284

result:

ok answer is '318420284'

Test #14:

score: 0
Accepted
time: 39ms
memory: 20224kb

input:

2147483547

output:

688759898

result:

ok answer is '688759898'

Test #15:

score: 0
Accepted
time: 62ms
memory: 21268kb

input:

5120103302

output:

116870489

result:

ok answer is '116870489'

Test #16:

score: 0
Accepted
time: 156ms
memory: 23716kb

input:

19834593299

output:

523663743

result:

ok answer is '523663743'

Test #17:

score: 0
Accepted
time: 298ms
memory: 23560kb

input:

52500109238

output:

195086665

result:

ok answer is '195086665'

Test #18:

score: 0
Accepted
time: 409ms
memory: 28300kb

input:

84848352911

output:

107959260

result:

ok answer is '107959260'

Test #19:

score: 0
Accepted
time: 461ms
memory: 28372kb

input:

99824435322

output:

0

result:

ok answer is '0'

Test #20:

score: 0
Accepted
time: 461ms
memory: 29436kb

input:

99999999354

output:

316301711

result:

ok answer is '316301711'

Test #21:

score: 0
Accepted
time: 453ms
memory: 28940kb

input:

100000000000

output:

396843576

result:

ok answer is '396843576'

Extra Test:

score: 0
Extra Test Passed