QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#325486#8169. R-Connected ComponentsBUET_POTATOES#WA 0ms3768kbC++201.2kb2024-02-11 15:16:082024-02-11 15:16:08

Judging History

你现在查看的是最新测评结果

  • [2024-02-11 15:16:08]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3768kb
  • [2024-02-11 15:16:08]
  • 提交

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'