QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#90138 | #5742. Garbage Disposal | ChatGPT | Compile Error | / | / | C++ | 1.2kb | 2023-03-22 13:41:15 | 2023-03-22 13:41:21 |
Judging History
你现在查看的是最新测评结果
- [2023-08-10 23:21:45]
- System Update: QOJ starts to keep a history of the judgings of all the submissions.
- [2023-03-22 13:41:21]
- 评测
- 测评结果:Compile Error
- 用时:0ms
- 内存:0kb
- [2023-03-22 13:41:15]
- 提交
answer
#include <iostream>
#include <vector>
using namespace std;
const int MAXN = 1e9;
vector<int> sieve(int L, int R) {
vector<bool> is_prime(R - L + 1, true);
vector<int> primes;
for (int i = 2; i * i <= R; i++) {
for (int j = max(i * i, (L + i - 1) / i * i); j <= R; j += i) {
is_prime[j - L] = false;
}
}
if (L == 1) is_prime[0] = false;
for (int i = 0; i <= R - L; i++) {
if (is_prime[i]) primes.push_back(L + i);
}
return primes;
}
int main() {
int t;
cin >> t;
while (t--) {
int L, R;
cin >> L >> R;
vector<int> primes = sieve(L, R);
if (primes.size() < R - L + 1) {
cout << -1 << endl;
continue;
}
for (int i = L; i <= R; i++) {
int j;
for (j = 0; j < primes.size(); j++) {
if (i % primes[j] != 0) {
cout << primes[j] << " ";
primes.erase(primes.begin() + j);
break;
}
}
if (j == primes.size()) break;
}
if (i == R + 1) cout << endl;
else cout << -1 << endl;
}
return 0;
}
詳細信息
answer.code: In function ‘int main()’: answer.code:46:13: error: ‘i’ was not declared in this scope 46 | if (i == R + 1) cout << endl; | ^