You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.4 KiB
C++
57 lines
1.4 KiB
C++
#define _CRT_SECURE_NO_WARNINGS
|
|
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
|
|
#include <bits/stdc++.h>
|
|
using namespace std;
|
|
int a[15], T, n, ans;
|
|
int c[15];
|
|
set<int> S;
|
|
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
|
|
void dfs(int st)
|
|
{
|
|
ans = max(ans, st);
|
|
for (int i = 0; i < n; i++)
|
|
if (!S.count(a[i]))
|
|
{
|
|
bool flag = true;
|
|
for (int j = 0; j < st; j++)
|
|
if (gcd(a[i], c[j]) != 1)
|
|
flag = false;
|
|
if (flag)
|
|
{
|
|
S.insert(a[i]);
|
|
c[st] = a[i];
|
|
dfs(st + 1);
|
|
S.erase(a[i]);
|
|
}
|
|
}
|
|
}
|
|
int main()
|
|
{
|
|
int T;
|
|
scanf("%d", &T);
|
|
while (T--)
|
|
{
|
|
ans = 0;
|
|
scanf("%d", &n);
|
|
for (int i = 0; i < n; i++) scanf("%d", a + i);
|
|
//dfs(0);
|
|
for (int i = 0; i < (1 << n); i++)
|
|
{
|
|
bool flag = true;
|
|
for (int j = 0; j < n; j++)
|
|
for (int k = j + 1; k < n; k++)
|
|
if ((i & (1 << j)) && (i & (1 << k)))
|
|
if (gcd(a[j], a[k]) != 1)
|
|
flag = false;
|
|
if (flag)
|
|
{
|
|
int cnt = 0;
|
|
for (int x = i; x; x -= x & -x) cnt++;
|
|
ans = max(ans, cnt);
|
|
}
|
|
}
|
|
cout << ans << endl;
|
|
}
|
|
return 0;
|
|
}
|