QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#569831#9309. GraphjeffqiWA 23ms10972kbC++202.4kb2024-09-17 11:19:062024-09-17 11:19:06

Judging History

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

  • [2024-09-17 11:19:06]
  • 评测
  • 测评结果:WA
  • 用时:23ms
  • 内存:10972kb
  • [2024-09-17 11:19:06]
  • 提交

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 umap __gnu_pbds::gp_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;
		umap<ll,umap<int,ll>> mp;
		auto get_mp = [&](auto &&self,ll x,int k) -> ll {
			if (x <= 1) {
				return x;
			}
			if (!k) {
				return (x+1)/2;
			}
			if (x <= N && 1ll*p[k]*p[k] >= x) {
				return upper_bound(all(p),x)-p.begin()+1-(k+1);
			}
			if (mp[x].find(k) == mp[x].end()) {
				mp[x][k] = self(self,x,k-1)-self(self,x/p[k],k-1);
			}
			return mp[x][k];
		};
		auto get_p = [&](ll x) -> ll {
			if (x <= 1) {
				return x;
			}
			int k = upper_bound(all(p),sqrt(1.L*x))-p.begin();
			return get_mp(get_mp,x,k)+k+1;
		};
		auto get = [&](ll x) {
			ll res = get_p(x)-get_p(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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4

output:

8

result:

ok answer is '8'

Test #2:

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

input:

2

output:

1

result:

ok answer is '1'

Test #3:

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

input:

123

output:

671840470

result:

ok answer is '671840470'

Test #4:

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

input:

233

output:

353738465

result:

ok answer is '353738465'

Test #5:

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

input:

5981

output:

970246821

result:

ok answer is '970246821'

Test #6:

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

input:

86422

output:

897815688

result:

ok answer is '897815688'

Test #7:

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

input:

145444

output:

189843901

result:

ok answer is '189843901'

Test #8:

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

input:

901000

output:

819449452

result:

ok answer is '819449452'

Test #9:

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

input:

1000000

output:

113573943

result:

ok answer is '113573943'

Test #10:

score: -100
Wrong Answer
time: 23ms
memory: 10972kb

input:

23333333

output:

620945766

result:

wrong answer expected '949849384', found '620945766'