結果

問題 No.2125 Inverse Sum
ユーザー tsugutsugutsugutsugu
提出日時 2023-02-19 01:57:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 327 ms / 2,000 ms
コード長 999 bytes
コンパイル時間 1,705 ms
コンパイル使用メモリ 177,636 KB
実行使用メモリ 6,300 KB
最終ジャッジ日時 2023-09-27 13:08:08
合計ジャッジ時間 5,140 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 3 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 327 ms
6,300 KB
testcase_28 AC 287 ms
5,664 KB
testcase_29 AC 101 ms
4,556 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 287 ms
5,716 KB
testcase_32 AC 12 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int main() {
    long long p, q;
    cin >> p >> q;
    vector<long long> div;
    for (long long i = 1; i * i <= q; i++) {
        if (q % i == 0) {
            div.push_back(i);
            if (q / i != i) {
                div.push_back(q / i);
            }
        }
    }
    sort(div.begin(), div.end());
    set<pair<long long, long long>> ans;
    for (int i = 0; i < (int) div.size(); i++) {
        for (int j = 0; j <= i; j++) {
            long long x = div[i] * div[j];
            long long y = q * q / x;
            if ((x + q) % p == 0 && (y + q) % p == 0) {
                long long A = (x + q) / p;
                long long B = (y + q) / p;
                ans.insert(make_pair(A, B));
                if (A != B) {
                    ans.insert(make_pair(B, A));
                }
            }
        }
    }
    cout << ans.size() << '\n';
    for (auto x : ans) {
        cout << x.first << ' ' << x.second << '\n';
    }
}
0