結果

問題 No.1626 三角形の構築
ユーザー kwm_tkwm_t
提出日時 2021-07-24 00:26:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,550 bytes
コンパイル時間 2,049 ms
コンパイル使用メモリ 178,980 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2024-04-20 16:07:58
合計ジャッジ時間 5,659 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
10,624 KB
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
//#include "atcoder/all"
using namespace std;
//using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
//using mint = modint998244353;
//const int mod = 998244353;
//const int INF = 1e9;
//const long long LINF = 1e18;
//const bool debug = false;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define endl "\n"
#define P pair<int,int>
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
long long cheker(long long n) {
	if (n < 0)return -1;
	long long ret = 1;
	for (long long i = 2; i*i <= n; i++) {
		int c = 0;
		while (n%i == 0) { // 素数で割り切れなくなるまで割っていく
			c++;//割った個数を配列に足す
			n /= i;
		}
		if (1 == c % 2) return -1;
		rep(j, c / 2) ret *= i;
		if (1 == n) break;
	}
	if (1 != n)return -1;
	return ret;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int q; cin >> q;
	while (q--) {
		long long s, t; cin >> s >> t;
		long long r = s * s * 16;
		if (0 != r % t) {
			cout << 0 << endl;
			continue;
		}
		r /= t;
		vector<long long>vx;
		for (long long i = 1; i*i <= r; ++i) {
			if (0 != r % i)continue;
			vx.push_back(i);
			if (r != i * i)vx.push_back(r / i);
		}
		sort(all(vx));
		//r = x*y*(t-x-y)
		set<pair<long long, pair<long long, long long>>>ans;
		rep(i, vx.size()) {
			long long x = vx[i];
			long long rx = r / x;
			//rx = y(t-x-y)
			//y=((t-x)±sqrt((x-t)^2-4*rx))/2
			long long sq = cheker((x - t) *(x - t) - 4 * rx);
			if (-1 == sq)continue;
			if (0 != abs(t - x - sq) % 2)continue;
			rep(j, 2) {
				long long y = (t - x - sq) / 2;
				if (1 == j) (t - x + sq) / 2;
				if (y > 0) {
					long long z = t - x - y;
					if (z > 0) {
						if ((0 == (abs(x - y) % 2)) && (0 == (abs(x - z) % 2))) {
							vector<int>abc(3);
							abc[0] = (x + y) / 2;
							abc[1] = (x + z) / 2;
							abc[2] = (y + z) / 2;
							sort(all(abc));
							ans.insert({ abc[0],{abc[1],abc[2]} });
						}
					}
				}
			}
		}
		cout << ans.size() << endl;
		for (auto abc : ans) {
			cout << abc.first << " " << abc.second.first << " " << abc.second.second << endl;
		}
	}
	return 0;
}
0