QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#610784#9309. GraphwjcWA 2ms9868kbC++142.3kb2024-10-04 17:23:342024-10-04 17:23:40

Judging History

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

  • [2024-10-04 17:23:40]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:9868kb
  • [2024-10-04 17:23:34]
  • 提交

answer

#include <bits/stdc++.h>
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef __int128 LLL;
typedef std::pair<int, int> pii;
typedef std::pair<LL, int> pli;
typedef std::pair<LL, LL> pll;
#define fi first
#define se second
#define MP std::make_pair
LL read() {
	LL s = 0; int f = 1;
	char c = getchar();
	while (!(c >= '0' && c <= '9'))
		f ^= (c == '-'), c = getchar();
	while (c >= '0' && c <= '9')
		s = s * 10 + (c ^ 48), c = getchar();
	return f ? s : -s;
} 
const LL INF = 0x3f3f3f3f3f3f3f3fll;
const int N = 4e5 + 7, MOD = 998244353;
template<typename T> T& Fmax(T& x, T y) { return x = x < y ? y : x; };
template<typename T> T& Fmin(T& x, T y) { return x = x < y ? x : y; };
auto fplus = [](LL x, LL y) { return x + y < MOD ? x + y : x + y - MOD; };
auto fminus = [](LL x, LL y) { return x < y ? x - y + MOD : x - y; };
auto Fplus = [](LL &x, LL y) { x = fplus(x, y); };
auto Fminus = [](LL &x, LL y) { x = fminus(x, y); };

LL fpow(LL x, LL y = MOD - 2) {
	LL ans = 1;
	for (; y; x = x * x % MOD, y >>= 1)
		if (y & 1) ans = ans * x % MOD;
	return ans;
}

bool isp[N];
LL n, m, tot, pr[N], f[2][N], ans = 1; 

LL id(LL x, LL y) { return x ? n / y : y; }
pll ID(LL x) { return x <= m ? MP(0, x) : MP(1, n / x); }

void Euler(int x) {
	memset(isp, 1, sizeof(isp));
	for (int i = 2; i <= x; i ++) {
		if (isp[i]) pr[++ tot] = i;
		for (int j = 1; j <= tot && i * pr[j] <= x; j ++) {
			isp[i * pr[j]] = false;
			if (i % pr[j] == 0) break;
		}
	}
} 

int main() {
	n = read(), Euler(m = sqrt(n));
	for (int i = 0; i <= 1; i ++)
		for (int j = 1; j <= m; j ++) f[i][j] = n / id(i, j) - 1;
	for (int i = 1; i <= tot; i ++) {
		LL lim = n / (pr[i] * pr[i]);
		for (int j = 1; j <= m && id(0, j) <= lim; j ++) {
			pll t = ID(id(0, j) * pr[i]);
			f[0][j] += i - 1 - f[t.fi][t.se]; 
		}
		for (int j = m; j && id(1, j) <= lim; j --) {
			pll t = ID(id(1, j) * pr[i]);
			f[1][j] += i - 1 - f[t.fi][t.se]; 
		}
	}
	for (LL l = 1, r, k; l <= n / 3; l = r + 1) {
		r = n / (n / l), k = n / l;
		pll t = ID(l); LL c = f[t.fi][t.se];
		if (l * 2 <= n) t = ID(l * 2), c -= f[t.fi][t.se];
//		std::cout << l << ' ' << r << ' ' << k << ' ' << c << '\n';
		LL f = fpow(k, c) * (k - c - 1) % MOD;
		ans = ans * fpow(f, r - l + 1) % MOD;
	}
	std::cout << ans << '\n';
	return 0;
}
 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 9868kb

input:

4

output:

8

result:

ok answer is '8'

Test #2:

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

input:

2

output:

1

result:

ok answer is '1'

Test #3:

score: -100
Wrong Answer
time: 2ms
memory: 8088kb

input:

123

output:

0

result:

wrong answer expected '671840470', found '0'