結果

問題 No.2358 xy+yz+zx=N
ユーザー LeoPro
提出日時 2023-06-23 21:32:33
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,046 ms / 2,000 ms
コード長 1,142 bytes
コンパイル時間 2,133 ms
コンパイル使用メモリ 197,348 KB
最終ジャッジ日時 2025-02-15 00:38:32
ジャッジサーバーID
(参考情報)
judge1 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

#ifdef LOCAL
  #define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>

#define int long long

using namespace std;
using ll = long long;

void solve();

template<typename ...Args>
void println(Args... args) {
    apply([](auto &&... args) { ((cout << args << ' '), ...); }, tuple(args...));
    cout << '\n';
}

int32_t main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    int t = 1;
//    cin >> t;
    for (int tc = 0; tc < t; ++tc) {
        solve();
    }
    return 0;
}

void solve() {
    int n;
    cin >> n;
    vector<array<int32_t, 3>> res;
    for (int x = 0; 3 * x * x <= n; ++x) {
        for (int y = x + !x; x * y <= n && y <= n; ++y){
            if ((n - x * y) % (x + y)) continue;
            int z = (n - x * y) / (x + y);
            if (z < y) continue;
            array<int32_t, 3> ans{(int32_t)x, (int32_t)y, (int32_t)z};
            do{
                res.push_back(ans);
            } while (next_permutation(ans.begin(), ans.end()));
        }
    }
    cout << res.size() << '\n';
    for (auto [x, y, z] : res) {
        cout << x << ' ' << y << ' ' << z << '\n';
    }
    cout << endl;
}
0