結果

問題 No.2125 Inverse Sum
ユーザー t98slider
提出日時 2022-11-18 22:43:43
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,014 bytes
コンパイル時間 1,681 ms
コンパイル使用メモリ 175,048 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-20 03:11:50
合計ジャッジ時間 5,656 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20 WA * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll P, Q, g;
    cin >> P >> Q;
    g = __gcd(P, Q);
    P /= g, Q /= g;
    auto sqrtll = [&](ll v){
        if(v < 0)return -1ll;
        ll v2 = sqrt(v);
        for(int i = -15; i <= 15; i++){
            if((v2 + i) * (v2 + i) == v)return v2 + i;
        }
        return -1ll;
    };
    vector<pair<ll,ll>> ans;
    for(ll i = 1; i <= 10000000 && i * i * P * P <= 1000000000000000000ll; i++){
        ll d = sqrtll(i * i * P * P - 4 * Q * i );
        if(d == -1)continue;
        if((i * P + d) & 1)continue;
        ans.emplace_back((i * P - d) >> 1, (i * P + d) >> 1);
        ans.emplace_back((i * P + d) >> 1, (i * P - d) >> 1);
    }
    sort(ans.begin(), ans.end());
    ans.erase(unique(ans.begin(), ans.end()), ans.end());
    cout << ans.size() << '\n';
    for(int i = 0; i < ans.size(); i++){
        cout << ans[i].first << ' ' << ans[i].second << '\n';
    }
}
0