零分TLE 1.20S 求大佬帮帮
查看原帖
零分TLE 1.20S 求大佬帮帮
1468496
skykissheep楼主2025/8/5 15:03

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

vector<pair<ll,ll>> solve(ll n) {
    vector<pair<ll,ll>> res;
    ll x = 0, y = sqrt(n);
    while(x <= y) {
        ll sum = x*x + y*y;
        if(sum == n) {
            res.emplace_back(x, y);
            x++;
            y--;
        } else if(sum < n) {
            x++;
        } else {
            y--;
        }
    }
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int T;
    cin >> T;
    while(T--) {
        ll n;
        cin >> n;
        auto ans = solve(n);
        for(auto [x,y] : ans) {
            cout << "(" << x << "," << y << ") ";
        }
        cout << "\n";
    }
    return 0;
}

2025/8/5 15:03
加载中...