QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#736491#9619. 乘积,欧拉函数,求和OIer_kzc#WA 12ms4092kbC++172.3kb2024-11-12 11:21:192024-11-12 11:21:20

Judging History

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

  • [2024-11-12 11:21:20]
  • 评测
  • 测评结果:WA
  • 用时:12ms
  • 内存:4092kb
  • [2024-11-12 11:21:19]
  • 提交

answer

#include <stdio.h>
#include <string.h>
#include <assert.h>

#include <vector>
#include <algorithm>

#define LOG(FMT...) fprintf(stderr, FMT)

#define eb emplace_back

using namespace std;

typedef long double LDB;

typedef long long LL;
constexpr int N = 32768, PC = 450, M = 3001;
constexpr int mod = 998244353;

int n, a[N], res;
int pid[M], pr[PC], cnt;
bool was[M];
int f[N], g[N];
char pc[N];

constexpr int neg(int x) {
	return x ? mod - x : x;
}

constexpr int inv(int x, int k = mod - 2) {
	int r = 1;
	while (k) {
		if (k & 1) {
			r = x * (LL)r % mod;
		}
		x = x * (LL)x % mod;
		k >>= 1;
	}
	return r;
}

void Add(int &x, int y) {
	if ((x += y) >= mod) {
		x -= mod;
	}
}

void Fav(int &x, int y, int z) {
	x = (x + y * (LL)z) % mod;
}

void sieve() {
	for (int x = 2; x < M; ++x) {
		if (!was[x]) {
			pid[x] = cnt;
			pr[cnt++] = x;
		}
		for (int k = 0; x * pr[k] < M; ++k) {
			was[x * pr[k]] = true;
			if (!(x % pr[k])) {
				break;
			}
		}
	}
}

struct Pair {
	int s, x;
	Pair() {}
	Pair(int _s, int _x) : s(_s), x(_x) {}
};
vector<Pair> ve[PC], emp;

void decomp(int x, int &s, int &k) {
	for (int d = 2; d <= x; ++d) {
		if (x % d) {
			continue;
		}
		while (!(x % d)) {
			x /= d;
		}
		int t = pid[d];
		if (t > 14) {
			assert(k == -1);
			k = t;
		} else {
			s |= 1 << t;
		}
	}
}

int main() {
	sieve();
	scanf("%d", &n);
	for (int i = 0, x; i < n; ++i) {
		scanf("%d", &x);
		int s = 0, k = -1;
		decomp(x, s, k);
		if (~k) {
			ve[k].eb(s, x);
		} else {
			emp.eb(s, x);
		}
	}
	f[0] = 1;
	for (auto [t, x] : emp) {
		for (int s = M - 1; ~s; --s) {
			Fav(f[s | t], f[s], x);
		}
	}
	for (int k = 15; k < cnt; ++k) {
		for (auto [t, x] : ve[k]) {
			for (int s = M - 1; ~s; --s) {
				Fav(g[s | t], g[s], x);
			}
			x -= x / pr[k];
			for (int s = 0; s < M; ++s) {
				Fav(g[s | t], f[s], x);
			}
		}
		for (int s = 0; s < M; ++s) {
			Add(f[s], g[s]);
		}
		memset(g, 0, M << 2);
	}
	for (int s = 0; s < M; ++s) {
		pc[s] = pc[s >> 1] ^ (s & 1);
		int v = f[s];
		if (!v) {
			continue;
		}
		for (int i = 0; i < 15; ++i) {
			if (s >> i & 1) {
				v = v * (LL)(mod + 1ll - inv(pr[i])) % mod;
			}
		}
		Add(res, v);
	}
	printf("%d\n", res);
	return 0;
}

详细

Test #1:

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

input:

5
1 6 8 6 2

output:

892

result:

ok single line: '892'

Test #2:

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

input:

5
3 8 3 7 8

output:

3157

result:

ok single line: '3157'

Test #3:

score: -100
Wrong Answer
time: 12ms
memory: 4092kb

input:

2000
79 1 1 1 1 1 1 2803 1 1 1 1 1 1 1609 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2137 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 613 1 499 1 211 1 2927 1 1 1327 1 1 1123 1 907 1 2543 1 1 1 311 2683 1 1 1 1 2963 1 1 1 641 761 1 1 1 1 1 1 1 1 1 1 1 1489 2857 1 1 1 1 1 1 1 1 1 1 1 1 1 967 1 821 1 1 1 1 2143 1861...

output:

56649673

result:

wrong answer 1st lines differ - expected: '50965652', found: '56649673'