Sky Code
Time Limit: 1000MS |
|
Memory Limit: 65536K |
Total Submissions: 2085 |
|
Accepted: 665 |
Description
Stancu likes space travels but he is a poor software developer and would never be able to buy his own spacecraft. That's why he's preparing to steal the spacecraft of Petru. There is only one problem–petru have locked the spacecraft with a sophisticated cryptosystem based on the ID numbers of T He stars from the Milky-the-Galaxy. For breaking the system Stancu have to check all subset of four stars such that the only common divisor of their numbers I S 1. Nasty, isn ' t it? Fortunately, Stancu have succeeded to limit the number of the The interesting stars to N but, any, the possible subsets of Four stars can be too many. Help him to find their number and to decide if there are a chance to break the system.
Input
In the input file several test cases is given. For each test case on the first line the number N of interesting stars is given (1≤n≤10000). The second line of the test case contains the list of ID numbers of the interesting stars, separated by spaces. Each ID was a positive integer which is no greater than 10000. The input data terminate with the end of file.
Output
For each test case, the program should print one and the number of subsets with the asked property.
Sample Input
42 3 4 5 42 4 6 8 72 3 4 5 7 6 8
Sample Output
1 0 34
Idea: the principle of tolerance and repulsion;
Since the given data range is 10000, we first hit the prime number within the table 10000;
Then we decompose each number, find out its various mass factors, and then violent combination of each number of the qualitative factor, in the BT array record number, that is, bt[i],i this number can be divided by the number of the preceding
Finally, from 1 cycles to 10000, you can get the number of non-demand, the total minus on the line.
Since each number is only 10000, his quality factor will not exceed 8, then the complexity is (n*28);
1#include <stdio.h>2#include <algorithm>3#include <iostream>4#include <string.h>5#include <queue>6#include <stack>7#include <map>8#include <math.h>9 using namespacestd;TentypedefLong LongLL; One BOOLprime[10005]= {0}; A intans[10005]; - intaa[10005]; - intbt[10005]; the intcc[10005]= {0}; - BOOLdd[10005]= {0}; -queue<int>que; - intMainvoid) + { - inti,j,k; + for(i=2; i< $; i++) A { at for(J=i; i*j<=10000; J + +) - { -prime[i*j]=true; - } - } - intCnt=0; in for(i=2; i<=10000; i++) - { to if(!Prime[i]) + { -ans[cnt++]=i; the } * } $ while(SCANF ("%d", &k)! =EOF)Panax Notoginseng { -Memset (BT,0,sizeof(BT)); the for(i=0; i<k; i++) + { Ascanf"%d",&aa[i]); the } + for(i=0; i<k; i++) - { $ intnn=Aa[i]; $ intt=0; - intflag=0; - while(nn>1) the { - if(flag==0&&nn%ans[t]==0)Wuyi { theflag=1; - Que.push (ans[t]); WuNn/=Ans[t]; - } About Else if(nn%ans[t]==0) $ { -Nn/=Ans[t]; -flag=1; - } A Else + { theflag=0; -t++; $ } the } the if(nn>1) the { the Que.push (NN); - } in intxx=0; the while(!que.empty ()) the { Aboutcc[xx++]=Que.front (); the Que.pop (); the } the intx; + inty; - for(x=1; X<= (1<<XX)-1; X + +) the {Bayi intak=1; the intvv=0; the for(j=0; j<xx; J + +) - { - if(x& (1<<j)) the { thevv++; theak*=Cc[j]; the } - } thebt[ak]+=1; the if(vv%2) thedd[ak]=true;94 } the } theLL sum=0; theLL sum1=0;98 for(i=2; i<=10000; i++) About { - if(bt[i]>=4)101 {102ll nn= (LL) bt[i]* (LL) (bt[i]-1) * (LL) (bt[i]-2) * (LL) (bt[i]-3)/ -;103 if(Dd[i])104sum+=nn; the Elsesum-=nn;106 }107 }108sum1= (LL) k* (LL) (K-1) * (LL) (K-2) * (LL) (K-3)/ -;109sum1-=sum; theprintf"%lld\n", sum1);111 } the return 0;113}
Sky Code (poj3904)