Skip to content

Commit 53cc78d

Browse files
authored
Create 2018-G-A.cpp
1 parent b560b9e commit 53cc78d

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

kick-start/2018-G-A.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
const int MAXN = 2e5+10;
5+
typedef long long LL;
6+
void solve(){
7+
int n;
8+
cin >> n;
9+
10+
vector<LL> num(n,0);
11+
for(int i=0; i<n ; ++i)
12+
{
13+
cin >> num[i];
14+
}
15+
sort(num.begin(),num.end());
16+
LL ans =0;
17+
LL zeros =0;
18+
for(int i=0 ; i<n ; ++i){
19+
if(!num[i])
20+
{
21+
zeros++;
22+
continue;
23+
}
24+
for(int j=i+1 ; j<n;++j){
25+
LL k = num[i] * num[j];
26+
ans+= upper_bound(num.begin()+j+1,num.end(),k) - lower_bound(num.begin()+j+1,num.end(),k);
27+
28+
}
29+
}
30+
ans += (zeros -1) * zeros /2 * (n - zeros);
31+
ans += (zeros -1) * zeros * (zeros -2)/6;
32+
cout << ans << '\n';
33+
}
34+
35+
int main(){
36+
ios :: sync_with_stdio(0);
37+
cin.tie(0);
38+
// cout.tie(0);
39+
std::cout.precision(10);
40+
std::cout.setf( std::ios::fixed, std:: ios::floatfield );
41+
42+
int T;
43+
cin >> T;
44+
for(int tt =1 ; tt <=T ; ++tt)
45+
{
46+
cout << "Case #" << tt << ": ";
47+
solve();
48+
}
49+
50+
51+
return 0;
52+
}

0 commit comments

Comments
 (0)