QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#381172 | #6512. Completely Multiplicative Function | james1BadCreeper | WA | 6ms | 13672kb | C++14 | 1.4kb | 2024-04-07 16:24:26 | 2024-04-07 16:24:26 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int v[N], tot, pri[N];
int a[N], cnt[N];
int id[N];
int main(void) {
ios::sync_with_stdio(0);
for (int i = 2; i < N; ++i) {
if (!v[i]) pri[++tot] = i;
for (int j = 1; j <= tot && i * pri[j] < N; ++j) {
v[i * pri[j]] = 1;
if (i % pri[j] == 0) break;
}
}
int T; cin >> T;
while (T--) {
int n, k; cin >> n >> k;
if (n % 2 != k % 2) { cout << "-1\n"; continue; }
int t = (n - k) / 2;
for (int i = 1; i <= n; ++i) a[i] = 1;
int m = upper_bound(pri + 1, pri + tot + 1, n) - pri - 1;
for (int i = 1; i <= m; ++i) cnt[i] = (n / pri[i] + 1) / 2, id[i] = i;
sort(id + 1, id + m + 1, [&](int x, int y) { return cnt[x] < cnt[y]; });
bool flg = 0;
for (int i = m; i >= 1; --i) if (t >= cnt[id[i]]) {
bool is = 0;
if (!flg) { t -= cnt[id[i]]; flg = 1; is = 1; }
else if (pri[id[i]] * 3 > n) t -= cnt[id[i]], is = 1;
if (is) {
// cout << pri[id[i]] << " ET\n";
for (int j = 1; j * pri[id[i]] <= n; ++j)
if (j & 1) a[j * pri[id[i]]] *= -1;
}
}
for (int i = 1; i <= n; ++i) cout << a[i] << " \n"[i == n];
assert(t == 0);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 6ms
memory: 13672kb
input:
4 4 2 10 0 10 1 10 10
output:
1 1 -1 1 1 -1 1 1 -1 -1 -1 1 1 -1 -1 1 1 1 1 1 1 1 1 1 1
result:
wrong answer f[8] != f[2] * f[4] (test case 2)