-
Notifications
You must be signed in to change notification settings - Fork 12
/
ABCDEF.cpp
56 lines (51 loc) · 1.18 KB
/
ABCDEF.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
/*
a*b+c=d*(e+f)
store the value of left equation in a vector and right in another one !!
use binary search to find the matching value and add in our solution
here we have used lower and upper bound to calculate all mathing range
*/
#include<bits/stdc++.h>
using namespace std;
#define MAX 102
int n,x[MAX],lower,higher;
long long res=0LL;
vector<int>s1,s2;
int main()
{
scanf("%d",&n);
for (int i=0;i<n;i++)
{
scanf("%d",&x[i]);
}
for (int i=0;i<n;i++)
{
for (int j=0;j<n;j++)
{
for (int k=0;k<n;k++)
{
s1.push_back(x[i]*x[j]+x[k]);
}
}
}
for (int i=0;i<n;i++)
{
for (int j=0;j<n;j++)
{
for (int k=0;k<n;k++)
{
if (x[k]==0) continue; // d can't be zero
s2.push_back((x[i]+x[j])*x[k]);
}
}
}
sort(s1.begin(),s1.end());
sort(s2.begin(),s2.end());
for (int i=0;i<s1.size();i++)
{
lo=lower_bound(s2.begin(),s2.end(),s1[i])-s2.begin();
hi=upper_bound(s2.begin(),s2.end(),s1[i])-s2.begin();
res+=(hi-lo);
}
printf("%lld\n",res);
return 0;
}