-
Notifications
You must be signed in to change notification settings - Fork 3
/
11565-SimpleEquations.cpp
70 lines (59 loc) · 1.36 KB
/
11565-SimpleEquations.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <math.h>
#include <algorithm>
#include <iterator>
#include <stdio.h>
#include <cstring>
#include <cassert>
using namespace std;
#define SUPER_MAX 6000000000000000000
long long a,b,c, n;
long long A, B, C;
bool solve() {
for (a = -min(sqrt(B), sqrt(C)); a < -1; a++) {
if ( (B % -a) != 0) continue;
const long long aa = a * a;
for (b = -1; b > a; b--) {
c = A - a - b;
if (a * b > B / c) break;
const long long bb = b * b;
const long long cc = c * c;
if (C - aa - bb < cc) break;
if (B / a == b * c && C - aa - bb - cc == 0) return true;
}
}
for (a = 1; a < n; a++) {
const long long kvot = B / a;
if (B != a * kvot) continue;
const long long aa = a * a;
if (2 * aa > C) break;
for (b = a+1;; b++) {
c = A - a - b;
if (c <= b) break;
if (b * c > kvot) break;
const long long bb = b * b;
if (aa + bb > C) break;
const long long cc = c * c;
if (C == aa + bb + cc && kvot == b * c) return true;
}
}
return false;
}
int main() {
int m;
cin >> m;
while (m--) {
cin >> A >> B >> C;
n = pow(B, 0.34) + 2;
if (solve())
cout << a << " " << b << " " << c << endl;
else
cout << "No solution." << endl;
}
return 0;
}