結果

問題 No.2125 Inverse Sum
ユーザー Carpenters-CatCarpenters-Cat
提出日時 2022-11-18 23:23:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,197 bytes
コンパイル時間 2,345 ms
コンパイル使用メモリ 211,668 KB
実行使用メモリ 4,880 KB
最終ジャッジ日時 2023-10-20 08:24:36
合計ジャッジ時間 4,826 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 WA -
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 3 ms
4,348 KB
testcase_10 AC 3 ms
4,348 KB
testcase_11 WA -
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 3 ms
4,348 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 3 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 WA -
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 3 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 WA -
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
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 2 ms
4,348 KB
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void calc_ft(const vector<pair<ll, int>>& x, int id, ll y, vector<ll>& ret) {
    if (id == x.size()) {
        ret.push_back(y);
        return;
    }
    auto [f, c] = x[id];
    ll pk = 1;
    for (int i = 0; i <= c; i ++) {
        calc_ft(x, id + 1, y * pk, ret);
        pk *= f;
    }
}
int main () {
    ll P, Q;
    cin >> P >> Q;
    ll Q2 = Q * Q;
    vector<pair<ll, int>> fts;
    ll q = Q;
    for (ll x = 2; x * x <= Q; x ++) {
        if (Q % x) {
            continue;
        }
        int c = 0;
        while (Q2 % x == 0) {
            Q2 /= x;
            c ++;
        }
        while (q % x == 0) {
            q /= x;
        }
        fts.emplace_back(x, c);
    }
    if (q > 1) {
        fts.emplace_back(q, 2);
    }
    vector<ll> R;
    calc_ft(fts, 0, 1, R);
    vector<pair<ll, ll>> ans;
    Q2 = Q * Q;
    for (auto d : R) {
        ll d2 = Q2 / d;
        if (((d + Q) % P) ||((d2 + Q) % P)) {
            continue;
        }
        ans.emplace_back((d + Q) / P, (d2 + Q) / P);
    }
    cout << ans.size() << endl;
    for (auto [n, m] : ans) {
        cout << n << " " << m << endl;
    }
}
0