結果

問題 No.2125 Inverse Sum
ユーザー t98slidert98slider
提出日時 2022-11-18 22:43:43
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,014 bytes
コンパイル時間 2,529 ms
コンパイル使用メモリ 176,012 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-20 07:41:39
合計ジャッジ時間 6,310 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 298 ms
4,348 KB
testcase_01 AC 297 ms
4,348 KB
testcase_02 AC 298 ms
4,348 KB
testcase_03 AC 297 ms
4,348 KB
testcase_04 AC 297 ms
4,348 KB
testcase_05 WA -
testcase_06 AC 40 ms
4,348 KB
testcase_07 WA -
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 297 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 3 ms
4,348 KB
testcase_14 AC 14 ms
4,348 KB
testcase_15 AC 23 ms
4,348 KB
testcase_16 AC 4 ms
4,348 KB
testcase_17 AC 3 ms
4,348 KB
testcase_18 AC 43 ms
4,348 KB
testcase_19 AC 3 ms
4,348 KB
testcase_20 AC 3 ms
4,348 KB
testcase_21 AC 5 ms
4,348 KB
testcase_22 AC 10 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 WA -
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 298 ms
4,348 KB
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

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