結果

問題 No.2125 Inverse Sum
ユーザー Carpenters-CatCarpenters-Cat
提出日時 2022-11-19 02:52:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 293 ms / 2,000 ms
コード長 1,227 bytes
コンパイル時間 3,497 ms
コンパイル使用メモリ 214,288 KB
実行使用メモリ 4,836 KB
最終ジャッジ日時 2023-10-20 11:06:08
合計ジャッジ時間 4,651 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 AC 3 ms
4,348 KB
testcase_06 AC 3 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 3 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 10 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 3 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
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 AC 2 ms
4,348 KB
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 AC 293 ms
4,836 KB
testcase_28 AC 225 ms
4,752 KB
testcase_29 AC 185 ms
4,428 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 228 ms
4,752 KB
testcase_32 AC 176 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

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);
    sort(R.begin(), R.end());
    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