結果

問題 No.2358 xy+yz+zx=N
ユーザー inkyaman
提出日時 2024-03-25 23:53:52
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,729 ms / 2,000 ms
コード長 1,389 bytes
コンパイル時間 1,324 ms
コンパイル使用メモリ 121,448 KB
最終ジャッジ日時 2025-02-20 13:50:18
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <math.h>
#include <cmath>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <iomanip>
#include <climits>
#include <functional>
#include <cassert>
#include <tuple>
using namespace std;
using ll = long long;

ll N;

int main() {

    cin >> N;

    vector<tuple<ll,ll,ll>> vt;
    for(ll i = 1; i*i <= N; ++i) {
        if(N%i == 0) {
            vector<ll> v = {0,i,N/i};
            do {
                ll x = v[0];
                ll y = v[1];
                ll z = v[2];
                vt.push_back({x,y,z});
            } while(next_permutation(v.begin(),v.end()));
        }
    }

    for(ll x = 1; x*x <= N; ++x) {
        for(ll y = x; y <= N/x+1; ++y) {
            if(N-x*y > 0 && (N-x*y)%(x+y) == 0) {
                ll z = (N-x*y)/(x+y);
                if(z >= y) {
                    vector<ll> v = {x,y,z};
                    do {
                        ll xx = v[0];
                        ll yy = v[1];
                        ll zz = v[2];
                        vt.push_back({xx,yy,zz});
                    } while(next_permutation(v.begin(),v.end()));
                }
            }
        }
    }

    cout << vt.size() << endl;
    for(auto [x,y,z] : vt) cout << x << " " << y << " " << z << endl;

}

0