Topic Source: Light OJ 1356 Prime Independence
To give you the number of n number of the most elected to form a set so that any 2 number is not another number of the quality of several times x!=k*y
Train of thought: contradictory 2 number of edges and all the number of elements divided into the odd and even two parts of the quality factor parity to construct the bipartite graph parity or the number of the same couple must not be another number of the mass number of times
The judgment contradiction is first decomposed to each number factor such as X has A1 a P1 mass factor a2 a P2 qualitative factor. The number of qualitative factors for a PN factor X is A1+a2+...+an recorded as Sum
To determine whether there are x/p1 x/p2 ... x/p3 exist and their number of mass factors sum parity with different edges HK to find the maximum independent set
#include <cstdio> #include <cstring> #include <queue> #include <cmath> #include <algorithm
> Using namespace std;
const int MAXN = 500010;
const int MAXM = 40010;
const int INF = 999999999; struct Edge {int V, next;}
E[MAXN];
BOOL VIS[MAXN];
int PRIME[MAXM];
int A[MAXM];
int B[MAXN];
int P[MAXM];
int NUM[MAXM];
int FIRST[MAXM], CNT;
int CX[MAXM], CY[MAXM];
int DX[MAXM], DY[MAXM];
int n, dis;
void sieve (int n) {int m = sqrt (n+0.5);
memset (Vis, 0, sizeof (VIS));
Vis[0] = vis[1] = 1;
for (int i = 2; I <= m. i++) if (!vis[i) for (int j = i*i; J <= N; j = i) vis[j] = 1;
int get_primes (int n) {sieve (n);
int c = 0;
for (int i = 2; I <= n; i++) if (!vis[i]) prime[c++] = i;
return C;
} void Addedge (int u, int v) {e[cnt].v = v;
E[cnt].next = First[u];
First[u] = cnt++;
BOOL Search () {dis = INF;
memset (DX,-1, sizeof (DX));
memset (Dy,-1, sizeof (DY));
Queue <int> Q; for (int i = 1; I <= n; i++) {if (cx[i) = = 1 && (num[i]&1)) {Q.push (i);
Dx[i] = 0; }} while (! Q.empty ()) {int u = q.front ();
Q.pop ();
if (Dx[u] > dis) break;
for (int i = first[u]; I!=-1; i = e[i].next) {int v = E[I].V;
if (dy[v] = =-1) {Dy[v] = Dx[u] + 1;
if (cy[v] = = 1) {dis = dy[v];
else {Dx[cy[v]] = Dy[v] + 1;
Q.push (Cy[v]);
}} return dis!= INF;
bool Dfs (int u) {for (int i = first[u]; I!=-1; i = e[i].next) {int v = E[I].V;
if (dy[v] = = Dx[u] + 1) {Dy[v] = 0;
if (cy[v] = =-1 | | | DFS (CY[V])) {Cx[u] = V;
CY[V] = u;
printf ("**%d%d\n", U, v);
return true;
}} return false;
int match () {int ans = 0;
memset (CX,-1, sizeof (CX));
memset (CY,-1, sizeof (CY));
while (in Search ()) {for (int i = 1; I <= n; i++) {if (cx[i] = = 1 && (num[i]&1) && dfs (i))
ans++;
} return ans;
int main () {int cas = 1;
int T;
scanf ("%d", &t); int C = Get_primes (500000);
while (t--) {scanf ("%d", &n);
memset (b, 0, sizeof (b));
memset (num, 0, sizeof (num));
memset (1, sizeof (a);
CNT = 0;
for (int i = 1; I <= n; i++) {scanf ("%d", &a[i]);
Sort (a+1, a+n+1);
for (int i = 1; I <= n; i++) {B[a[i]] = i;
for (int i = 1; I <= n; i++) {int x = a[i];
int sum = 0;
int sum2 = 0; for (int j = 0; J < c && Prime[j]*prime[j] <= x j + +) {if (x% prime[j] = 0) {p[sum++] = pr
IME[J];
while (x% prime[j] = = 0) {x/= prime[j];
sum2++;
}} if (x > 1) {p[sum++] = x;
sum2++;
} Num[i] = sum2;
printf ("***%d\n", sum2);
for (int j = 0; J < sum; j +) {int temp = b[a[i]/p[j]];
if (temp > i) continue;
if (temp) {if ((sum2&1) = = (num[temp]&1)) continue;
printf ("%d%d\n", I, temp);
if ((sum2&1)) Addedge (i, temp); Else
Addedge (temp, i);
an int ans = match ();
printf ("Case%d:%d\n", cas++, N-ans);
return 0; }