Topic 3: Prime number correlationTime limit:2000msSingle Point time limit:1000msMemory Limit:256MBDescribe
Two numbers A and B (a<b) are referred to as prime number correlation, which refers to AXP = B, where p is a prime number. A set of S is called a prime correlation, which means that there are two prime number-related numbers in S, otherwise the s are not prime numbers. such as {2, 8, 17} prime numbers are irrelevant, but {2, 8, 16}, {3, 6} prime numbers are related. Now given a collection of s, ask the size of the largest subset of all prime number unrelated subsets of S.
Input
The first behavior is a number T, which is the number of data groups. Each group of data then contains two rows.
The first behavior n, the size of the set S. The second behavior is n integers, representing the number within the collection.
Output
For each set of data output line, the shape is "case #X: Y". X is the data number, starting with 1, Y is the size of the largest subset.
Data range
1≤t≤20
The number 22 in the set S is different and ranges from 1 to 500000.
Small Data
1≤n≤15
Big Data
1≤n≤1000
-
-
Sample input
-
-
352 4 8 16 3252 3 4 6 931 2 3
-
-
Sample output
-
Case #1:3Case #2:3Case #3:2
Seems to be Loj's original question,--
The maximal independent set is obtained by matching the two points.
#include <iostream>#include<algorithm>#include<cstring>#include<cstdio>#include<vector>#include<queue>#include<Set>#include<map>#include<string>#include<cmath>#include<cstdlib>#include<ctime>using namespacestd;#defineINF 0x3f3f3f3f#definell Long Long#defineN 1010#defineM 500000intn,m,k;intA[n];intVis[n];intMatch[n];intMpt[n][n];inttot;BOOLisprime[m+Ten];intprime[m+Ten];voidinit () {tot=0; memset (IsPrime,true,sizeof(IsPrime)); isprime[0]=isprime[1]=false; for(intI=2; i<=m;i++) { if(Isprime[i]) prime[tot++]=i; for(intj=0; j<tot;j++) { if(LL) i*prime[j]>m) Break; Isprime[i*prime[j]]=false; if(i%prime[j]==0) Break; } }}intDfsintu) { for(intj=1; j<=n;j++) { if(!vis[j] &&Mpt[u][j]) {Vis[j]=1; if(match[j]==-1||DFS (Match[j])) {Match[j]=u; return 1; } } } return 0;}BOOLJudgeintAintb) { if(a>b) Swap (A, a); if(b%a)return 0; intk=b/A; if(Isprime[k])return 1; return 0;}intMain () {init (); intT,icase=1; scanf ("%d",&T); while(t--) {scanf ("%d",&N); memset (MPT,0,sizeof(MPT)); for(intI=1; i<=n;i++) scanf ("%d",&A[i]); for(intI=1; i<=n;i++) { for(intj=i+1; j<=n;j++) { if(judge (A[i],a[j])) {Mpt[i][j]=1; Mpt[j][i]=1; }}} printf ("Case #%d:", icase++); intans=0; memset (Match,-1,sizeof(match)); for(intI=1; i<=n;i++) {memset (Vis,0,sizeof(VIS)); if(Dfs (i)) ans++; } printf ("%d\n", n-ans/2); } return 0;}
[2015 programming beauty] The first game C