QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#788335#9619. 乘积,欧拉函数,求和Bicycle_23WA 427ms4444kbC++232.4kb2024-11-27 16:35:302024-11-27 16:35:31

Judging History

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

  • [2024-11-27 16:35:31]
  • 评测
  • 测评结果:WA
  • 用时:427ms
  • 内存:4444kb
  • [2024-11-27 16:35:30]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'

constexpr int maxn = 2e5 + 5;
constexpr int mod = 998244353;
constexpr int prime[16] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53};

int qpow(int x, int y)
{
	int res = 1;
	while (y)
	{
		if (y & 1)
			res = res * x % mod;
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}

int lowbit(int x) { return x & (-x); }

void fwt_or(vector<int> &a, bool flag)
{
	int len = (int)a.size();
	for (int i = 2; i <= len; i <<= 1)
		for (int j = 0; j < len; j += i)
			for (int k = 0; k < i / 2; k++)
				if (flag)
				{
					int x = a[j + k], y = (a[j + k] + a[j + k + i / 2]) % mod;
					a[j + k] = x;
					a[j + k + i / 2] = y;
				}
				else
				{
					int x = a[j + k], y = ((mod - a[j + k]) % mod + a[j + k + i / 2]) % mod;
					a[j + k] = x;
					a[j + k + i / 2] = y;
				}
}

void mul_or(vector<int> &a, vector<int> &b)
{
	int len = 1;
	while (len < max((int)a.size(), (int)b.size()))
		len <<= 1;
	a.resize(len);
	b.resize(len);
	fwt_or(a, 1);
	fwt_or(b, 1);
	for (int i = 0; i < len; i++)
		a[i] = a[i] * b[i] % mod;
	fwt_or(a, 0);
}

void solve()
{
	int n;
	cin >> n;
	vector<int> a(n + 1, 0);
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	vector<array<int, 2>> f(0);
	for (int i = 1; i <= n; i++)
	{
		int x = a[i], w = 0;
		for (int j = 0; j < 16; j++)
		{
			if (x % prime[j] == 0)
				w |= (1ll << j);
			while (x % prime[j] == 0)
				x /= prime[j];
		}
		array<int, 2> res;
		if (x == 1)
			res = {w, a[i]};
		else
			res = {w, a[i] / x * (x - 1)};
		f.push_back(res);
	}
	vector<int> ans(1ll << 16, 0);
	ans[0] = 1;
	for (int i = 0; i < n; i++)
	{
		vector<int> tmp(1ll << 16, 0);
		for (int l = 0; l < (1ll << 16); l++)
		{
			int pos = l | f[i][0];
			tmp[pos] = (tmp[pos] + ans[l] * f[i][1]) % mod;
		}
		for (int l = 0; l < (1ll << 16); l++)
			ans[l] = (ans[l] + tmp[l]) % mod;
	}
	int sum = 0;
	for (int l = 0; l < (1ll << 16); l++)
	{
		int x = l, w = ans[l];
		while (x)
		{
			int pri = prime[(int)log2(lowbit(x))];
			x -= lowbit(x);
			int invp = qpow(pri, mod - 2);
			w = w * invp % mod * (pri - 1) % mod;
		}
		sum = (sum + w) % mod;
	}
	cout << sum;
}

signed main()
{
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(0);
	int _ = 1;
	// cin >> _;
	while (_--)
		solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 72ms
memory: 4208kb

input:

5
1 6 8 6 2

output:

892

result:

ok single line: '892'

Test #2:

score: 0
Accepted
time: 72ms
memory: 4212kb

input:

5
3 8 3 7 8

output:

3157

result:

ok single line: '3157'

Test #3:

score: 0
Accepted
time: 422ms
memory: 4208kb

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:

50965652

result:

ok single line: '50965652'

Test #4:

score: 0
Accepted
time: 427ms
memory: 4444kb

input:

2000
1 1 1 1 1 1 1 1 353 1 1 1 557 1 1 1 1 1 1 1 1 1 1 1 1423 1 1 1327 1 1 1 907 1 1 1 1 1 2971 1 1 1 2531 1 1 1 1 1 1 1 1 1 2099 1 1 1 1 1 1 1 1 1 1 1 1 1 1 199 2999 1 727 1 1 1 1 1 1 1 71 1 1 1 1 1 1 2503 1 176 1 1 1 1 1 1 1361 1013 1 1 1 1 1 1 1 2699 1 1 1 1 1 1 1 1 1 2897 1 1 1 1 1637 1 1 1367 1...

output:

420709530

result:

ok single line: '420709530'

Test #5:

score: 0
Accepted
time: 77ms
memory: 4196kb

input:

30
37 14 35 33 38 42 46 3 26 7 16 1 35 38 48 3 43 49 18 3 29 1 43 43 20 6 39 20 14 38

output:

262613273

result:

ok single line: '262613273'

Test #6:

score: 0
Accepted
time: 77ms
memory: 4276kb

input:

30
39 31 49 2 4 28 30 12 13 34 7 28 17 37 38 18 41 33 29 36 18 7 3 14 30 42 35 14 18 35

output:

234142118

result:

ok single line: '234142118'

Test #7:

score: -100
Wrong Answer
time: 106ms
memory: 4292kb

input:

200
53 37 234 248 66 30 64 181 38 130 250 27 199 226 43 185 207 241 38 296 68 18 145 20 64 127 57 30 168 267 221 116 115 192 17 26 5 63 3 127 52 48 229 58 69 111 20 244 234 35 48 217 179 189 89 60 285 106 43 104 36 28 62 281 104 38 281 264 140 275 105 20 203 271 222 262 123 10 82 263 118 254 229 222...

output:

119629509

result:

wrong answer 1st lines differ - expected: '617035263', found: '119629509'