QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#381277 | #6512. Completely Multiplicative Function | james1BadCreeper | RE | 7ms | 12000kb | C++14 | 1.9kb | 2024-04-07 16:43:53 | 2024-04-07 16:43:53 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 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) {
id[i] = i; int now = 1;
cnt[i] = 0;
for (int k = 1; now <= n / pri[i]; ++k) now *= pri[i], cnt[i] += (k & 1 ? 1 : -1) * n / now;
}
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]] * 2 > n || a[pri[id[i]] * 2] != -1) t -= cnt[id[i]], is = 1;
if (is) {
// cout << pri[id[i]] << " ET\n";
int now = 1;
for (int k = 1; now <= n / pri[id[i]]; ++k) {
now *= pri[id[i]];
for (int x = 1; x * now <= n; ++x)
a[x * now] *= -1;
}
// for (int j = 1; j * pri[id[i]] <= n; ++j)
// if (j & 1) a[j * pri[id[i]]] *= -1;
// for (int k = 1; k <= n; ++k) cout << a[k] << " \n"[k == n];
}
}
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: 100
Accepted
time: 7ms
memory: 12000kb
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:
ok ok (4 test cases)
Test #2:
score: -100
Runtime Error
input:
11475 1 0 1 1 2 0 2 1 2 2 3 0 3 1 3 2 3 3 4 0 4 1 4 2 4 3 4 4 5 0 5 1 5 2 5 3 5 4 5 5 6 0 6 1 6 2 6 3 6 4 6 5 6 6 7 0 7 1 7 2 7 3 7 4 7 5 7 6 7 7 8 0 8 1 8 2 8 3 8 4 8 5 8 6 8 7 8 8 9 0 9 1 9 2 9 3 9 4 9 5 9 6 9 7 9 8 9 9 10 0 10 1 10 2 10 3 10 4 10 5 10 6 10 7 10 8 10 9 10 10 11 0 11 1 11 2 11 3 11...
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 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 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 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 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 1 -1 ...