QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#610816#9309. GraphwjcWA 43ms12396kbC++142.4kb2024-10-04 17:32:432024-10-04 17:33:07

Judging History

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

  • [2024-10-04 17:33:07]
  • 评测
  • 测评结果:WA
  • 用时:43ms
  • 内存:12396kb
  • [2024-10-04 17:32:43]
  • 提交

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];
		LL f = (k == 3 ? 3 : fpow(k, c) * (k - c - 1) % MOD);
		ans = ans * fpow(f, r - l + 1) % MOD;
//		std::cout << l << ' ' << r << ' ' << k << ' ' << c << ' ' << f << ' ' << ans << '\n';
	}
	std::cout << ans << '\n';
	return 0;
}
 

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 8072kb

input:

4

output:

8

result:

ok answer is '8'

Test #2:

score: 0
Accepted
time: 1ms
memory: 6060kb

input:

2

output:

1

result:

ok answer is '1'

Test #3:

score: 0
Accepted
time: 1ms
memory: 8084kb

input:

123

output:

671840470

result:

ok answer is '671840470'

Test #4:

score: 0
Accepted
time: 1ms
memory: 8088kb

input:

233

output:

353738465

result:

ok answer is '353738465'

Test #5:

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

input:

5981

output:

970246821

result:

ok answer is '970246821'

Test #6:

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

input:

86422

output:

897815688

result:

ok answer is '897815688'

Test #7:

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

input:

145444

output:

189843901

result:

ok answer is '189843901'

Test #8:

score: 0
Accepted
time: 1ms
memory: 9852kb

input:

901000

output:

819449452

result:

ok answer is '819449452'

Test #9:

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

input:

1000000

output:

113573943

result:

ok answer is '113573943'

Test #10:

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

input:

23333333

output:

949849384

result:

ok answer is '949849384'

Test #11:

score: 0
Accepted
time: 5ms
memory: 10196kb

input:

102850434

output:

604886751

result:

ok answer is '604886751'

Test #12:

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

input:

998244353

output:

0

result:

ok answer is '0'

Test #13:

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

input:

1000000007

output:

318420284

result:

ok answer is '318420284'

Test #14:

score: 0
Accepted
time: 23ms
memory: 12396kb

input:

2147483547

output:

688759898

result:

ok answer is '688759898'

Test #15:

score: -100
Wrong Answer
time: 43ms
memory: 10440kb

input:

5120103302

output:

406301251

result:

wrong answer expected '116870489', found '406301251'