-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathB_Array_Reodering.cpp
60 lines (47 loc) · 1009 Bytes
/
B_Array_Reodering.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
#include<bits/stdc++.h>
#include<vector>
#include <algorithm>
#define ll long long
using namespace std;
int gcd(int a, int b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
int main() {
int t;
cin>>t;
while(t--){
int n;
cin>>n;
int a[n];
vector<int> odd;
vector<int> even;
for (int i = 0; i < n; i++)
{
int x;
cin>>x;
if(x%2==0)
{
even.push_back(x);
}
else
{
odd.push_back(x);
}
}
int o = odd.size();
int e = n - o;
long long int ans = e * o;//even*odd
for (int i = 0; i < o; i++)
{
for (int j = i+1; j < o; j++)
{
if((gcd(odd[i], 2*odd[j]))>1)
ans++;
}
}//odd
ans += (e * (e - 1) / 2);;//even
cout<<ans<<"\n";
}
}