QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#505212 | #5742. Garbage Disposal | chimera | WA | 0ms | 3812kb | C++14 | 1.4kb | 2024-08-04 22:21:43 | 2024-08-04 22:21:44 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll gcd(ll x, ll y) {
if(y == 0) return x;
return gcd(y, x % y);
}
int main() {
ll T; cin >> T;
for(ll t = 0; t < T; t++) {
ll L, R; cin >> L >> R;
if(L == R) {
cout << "-1\n"; continue;
}
ll p = -1;
for(ll i = L; i <= R; i++) {
bool prime = true;
for(ll tr = 2; tr*tr <= i; tr++) {
if(i%tr == 0) {prime = false; break;}
}
if(prime) {
p=i;break;
}
}
bool good = true;
vector<ll> ans;
if(p > 0) {
for(ll i = L; i <= R; i++) {
if(i != p) ans.push_back(p);
else {
if(p == L) ans.push_back(p+1);
else ans.push_back(p-1);
}
}
} else {
for(ll i = L; i <= R; i++) {
bool ok = false;
for(ll j = L; j <= R; j++) {
if(gcd(i,j)==1) {
ans.push_back(j); ok = true; break;
}
}
if(!ok) {
good = false; break;
}
}
}
if(!good) cout << "-1\n";
else {
for(auto x: ans) cout << x << " "; cout << "\n";
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3812kb
input:
3 1 5 10 13 100 100
output:
2 1 1 1 1 11 10 11 11 -1
result:
wrong answer answer has non-unique integers (test case 1)