QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#505213 | #5742. Garbage Disposal | chimera | WA | 0ms | 3728kb | C++14 | 1.6kb | 2024-08-04 22:22:53 | 2024-08-04 22:22:53 |
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(ll i = 0; i < ans.size(); i++) {cout << ans[i]; if(i == ans.size()-1) cout << "\n"; else cout << " ";}
//for(auto x: ans) cout << x << " "; cout << "\n";
}
}
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3728kb
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)