Test instructions: The smallest composite in the factor of the product of a series of numbers;
Idea: Game enumeration factor, enumeration to two when the end, estimated time-out, the result is a fork;
The decomposition of each number to take the minimum of two qualitative factors, if the number of less than 2, then does not exist;
#include <cstdio>#include<cstring>#include<vector>#include<algorithm>using namespacestd;intt,n,m;intnum[505];Const intmaxn=100000;intprime[maxn+1];voidGetprime () {memset (prime,0,sizeof(prime)); for(intI=2; i<=maxn;i++){ if(!prime[i]) prime[++prime[0]]=i; for(intj=1; j<=prime[0]&&prime[j]*i<=maxn;j++) {Prime[prime[j]*i]=1; if(i%prime[j]==0) Break; } }}Long Longfactor[ -][2];intCNT;intGetfactor (Long Longx) {CNT=0; Long Longtmp=x; for(intI=1;p rime[i]<=tmp/prime[i];i++) {factor[cnt][1]=0; if(tmp%prime[i]==0) {factor[cnt][0]=Prime[i]; while(tmp%prime[i]==0) {factor[cnt][1]++; TMP/=Prime[i]; } CNT++; } } if(tmp!=1) {factor[cnt][0]=tmp; Factor[cnt++][1]=1; } returnCNT;}intMain () {inti,j,k; Getprime (); scanf ("%d",&t); while(t--) {scanf ("%d",&N); Vector<int>ans; for(i=0; i<n;i++) {scanf ("%d",&Num[i]); Getfactor (Num[i]); for(j=0; j<cnt;j++){ while(factor[j][1]--) {ans.push_back (factor[j][0]); }}} sort (Ans.begin (), Ans.end ()); if(Ans.size () <2) {printf ("-1\n"); } Else{printf ("%i64d\n",(Long Long) ans[0]*ans[1]); } } return 0;}
Hdu 5428 The Factor (prime number screening composite decomposition)