QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#90140 | #5742. Garbage Disposal | ChatGPT | WA | 2ms | 3516kb | C++ | 1.3kb | 2023-03-22 13:42:05 | 2023-03-22 13:42:07 |
Judging History
answer
#include <iostream>
#include <vector>
using namespace std;
const int MAXN = 1e5 + 5;
int t, L, R;
vector<int> primes;
bool is_prime[MAXN];
void sieve() {
fill(is_prime, is_prime+MAXN, true);
is_prime[0] = is_prime[1] = false;
for (int i = 2; i < MAXN; i++) {
if (is_prime[i]) {
primes.push_back(i);
for (int j = i*2; j < MAXN; j += i) {
is_prime[j] = false;
}
}
}
}
int main() {
sieve();
cin >> t;
while (t--) {
cin >> L >> R;
vector<int> used(R-L+1);
int cnt = 0;
for (int i = 0; i < primes.size() && primes[i] <= R; i++) {
int p = primes[i];
int start = ((L-1)/p + 1) * p;
for (int j = start; j <= R; j += p) {
if (!used[j-L]) {
used[j-L] = 1;
cout << j;
cnt++;
if (cnt == R-L+1) {
cout << endl;
break;
} else {
cout << " ";
if (cnt % 10 == 0) cout << endl;
}
}
}
}
if (cnt != R-L+1) {
cout << -1 << endl;
}
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 3516kb
input:
3 1 5 10 13 100 100
output:
2 4 3 5 -1 10 12 11 13 100
result:
wrong answer Integer element y[5] equals to -1, violates the range [1, 5] (test case 1)