結果

問題 No.2358 xy+yz+zx=N
ユーザー inkyamaninkyaman
提出日時 2024-03-25 23:53:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,758 ms / 2,000 ms
コード長 1,389 bytes
コンパイル時間 1,296 ms
コンパイル使用メモリ 125,476 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-25 23:54:03
合計ジャッジ時間 10,930 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 1 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 7 ms
6,676 KB
testcase_08 AC 1,758 ms
6,676 KB
testcase_09 AC 1,739 ms
6,676 KB
testcase_10 AC 1,725 ms
6,676 KB
testcase_11 AC 1,705 ms
6,676 KB
testcase_12 AC 1,306 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

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