-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathB_Array_Reodering.cpp
More file actions
59 lines (56 loc) · 978 Bytes
/
B_Array_Reodering.cpp
File metadata and controls
59 lines (56 loc) · 978 Bytes
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
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve(ll n)
{
vector<ll> v1, v2;
for (int i = 0; i < n; i++)
{
ll x;
cin >> x;
if (x % 2 == 0)
{
v1.push_back(x);
}
else
{
v2.push_back(x);
}
}
for (int i = 0; i < v2.size(); i++)
{
v1.push_back(v2[i]);
}
ll count = 0;
for (int i = 0; i < v1.size(); i++)
{
if (v1[i] % 2 == 0)
{
count += n - i - 1;
}
else
{
for (int j = i + 1; j < v1.size(); j++)
{
if (__gcd(v1[i], v1[j]) > 1)
count++;
}
}
}
cout << count << endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t;
cin >> t;
while (t--)
{
ll n;
cin >> n;
solve(n);
}
return 0;
}