-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRecreation_Two.cpp
More file actions
71 lines (51 loc) · 1.24 KB
/
Copy pathRecreation_Two.cpp
File metadata and controls
71 lines (51 loc) · 1.24 KB
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
71
#include <cmath>
using namespace std;
class SqProd2Sum
{
public:
static std::vector<std::pair <long, long>> prod2Sum(long long a, long long b, long long c, long long d);
};
vector<pair<long, long>> SqProd2Sum::prod2Sum(long long a, long long b, long long c, long long d)
{
vector<pair<long, long>> res;
if(a==0 && b==0 && c==0 && d==0)
{
res.push_back({0,0});
return res;
}
long long left= a*a + b*b;
long long right = c*c+d*d;
long long prod = left*right;
long long case1=a*c;
long long case1_ = b*d;
long long case2= a*d;
long long case2_ = b*c;
if(a<0)
a*=-1;
if(b<0)
b*=-1;
if(c<0)
c*=-1;
if(d<0)
d*=-1;
cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
long i =0;
while(i*i<prod)
{
double k = prod;
k-=i*i;
if(sqrt(k)==floor(sqrt(k)))
{
if((i==abs(a*d-b*c) && sqrt(k)==a*c+b*d) || (i==abs(a*c-b*d) && sqrt(k)==a*d+b*c))
if(find_if(res.begin(), res.end(), [&k](auto e){return e.first==sqrt(k) || e.second==sqrt(k);})==res.end())
{
if(i<=sqrt(k))
res.push_back({i, sqrt(k)});
else
res.push_back({sqrt(k), i});
}
}
i++;
}
return res;
}