QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#90140#5742. Garbage DisposalChatGPTWA 2ms3516kbC++1.3kb2023-03-22 13:42:052023-03-22 13:42:07

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:42:07]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3516kb
  • [2023-03-22 13:42:05]
  • 提交

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;
}

Details

Tip: Click on the bar to expand more detailed information

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)