QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#325486 | #8169. R-Connected Components | BUET_POTATOES# | WA | 0ms | 3768kb | C++20 | 1.2kb | 2024-02-11 15:16:08 | 2024-02-11 15:16:08 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
vector<pii> getvec(int R){
vector<pii> vec;
for(int i = 0; i * i <= R; i++){
int x = i, y = sqrt(R - i * i);
if(x * x + y * y == R){
vec.emplace_back(x, y);
vec.emplace_back(y, x);
}
}
sort(vec.begin(), vec.end());
vec.resize(unique(vec.begin(), vec.end()) - vec.begin());
return vec;
}
void solve(int R){
auto vec = getvec(R);
// cout << R << endl;
// cout << "DX, DY" << endl;
// for(auto [x, y] : vec)cout << x << ' ' << y << endl;
if(vec.empty()){
cout << "inf\n";
return;
}
int gcd = 0;
set<int> s;
for(auto [x, y] : vec){
gcd = __gcd(gcd, x), gcd = __gcd(gcd, y);
s.insert((x + y) % 2);
}
if(2 * gcd * gcd == R){
cout << R << "\n";
return;
}
if(gcd % 2 == 0 || s.size() == 2)cout << gcd * gcd << "\n";
else cout << 2 * gcd * gcd << "\n";
}
int main(){
ios::sync_with_stdio(false); cin.tie(0);
int T;
cin >> T;
while(T--){
int R;
cin >> R;
solve(R);
}
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3768kb
input:
3 1 2 3
output:
2 2 inf
result:
wrong answer 1st words differ - expected: '1', found: '2'