結果

問題 No.1626 三角形の構築
ユーザー maine_honzuki
提出日時 2021-07-23 21:55:00
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 1,956 bytes
コンパイル時間 2,313 ms
コンパイル使用メモリ 213,224 KB
最終ジャッジ日時 2025-01-23 07:59:52
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 23 TLE * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

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

vector<pair<ll, ll>> prime_factorize(ll n) {
    vector<pair<ll, ll>> ret;
    for (ll i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            ll num = 0;
            while (n % i == 0) {
                num++;
                n /= i;
            }
            ret.push_back({i, num});
        }
    }
    if (n != 1)
        ret.push_back({n, 1});
    return ret;
}

ll S, T;
vector<pair<ll, ll>> V;
vector<vector<ll>> Pow;
set<vector<ll>> ans;

void maine(vector<ll> Len, int idx) {
    if (idx == V.size()) {
        for (auto&& l : Len) {
            l = T - l;
            if (l % 2 == 1 || l <= 0)
                return;
            l /= 2;
        }
        sort(begin(Len), end(Len));
        if (Len[0] + Len[1] > Len[2] && Len[1] + Len[2] > Len[0] && Len[2] + Len[0] > Len[1] && Len[0] + Len[1] + Len[2] == T)
            ans.insert(Len);
    } else {
        auto [n, m] = V[idx];
        for (int i = 0; i <= m; i++) {
            for (int j = 0; j <= m - i; j++) {
                int k = m - i - j;
                auto nxt = Len;
                nxt[0] *= Pow[idx][i];
                nxt[1] *= Pow[idx][j];
                nxt[2] *= Pow[idx][k];
                maine(nxt, idx + 1);
            }
        }
    }
}

void solve() {
    ans.clear();
    Pow.clear();
    cin >> S >> T;
    if ((16 * S * S) % T) {
        cout << 0 << endl;
        return;
    }
    V = prime_factorize(16 * S * S / T);
    for (auto&& [n, m] : V) {
        vector<ll> book(1, 1);
        for (int i = 0; i < m; i++) {
            book.emplace_back(n * book.back());
        }
        Pow.emplace_back(book);
    }
    maine({1, 1, 1}, 0);
    cout << ans.size() << endl;
    for (auto&& e : ans) {
        for (int i = 0; i < 3; i++) {
            cout << e[i] << " \n"[i == 2];
        }
    }
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
}
0