Sky Code
| Time Limit: 1000MS |
|
Memory Limit: 65536K |
| Total Submissions: 1694 |
|
Accepted: 523 |
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
Test instructions: given n number a1,a2,a3,...,An, from which four numbers are selected, so that their greatest common divisor between 1, ask how many kinds of extraction?
Problem-solving ideas: For each number of AI, we decompose it into qualitative factor, and then use 2^k algorithm to find out all the number composed of factorization, and record the number of qualitative factors, and finally use the principle of tolerance to solve;
Reference code:
#include <iostream> #include <string.h>using namespace std; #define MAX_N 10000+5#define Max_factor 16typedef long ll;int n,f[max_n],count[max_n],factor[max_factor],factor_num[max_n];void solve (int a) {int k=0;for (int i=2;i*i<=a;i++) {//Mass factorization if (a%i==0) {factor[k++]=i;while (a%i==0) a/=i;}} if (a>1) factor[k++]=a;for (int i=1;i< (1<<k); i++) {//2^k algorithm int mul=1,bits=0;for (int j=0;j<k;j++) {if (i & (1<<j)) {bits++;mul*=factor[j];}} Count[mul]++;factor_num[mul]=bits;}} LL Cal (ll a) {return a * (A-1) * (a-2) * (a-3)/24;} int main () {while (cin>>n) {for (int i=0;i<n;i++) Cin>>f[i];memset (count,0,sizeof (count)); Memset ( Factor_num,0,sizeof (Factor_num)), for (int i=0;i<n;i++) solve (F[i]), LL ans=cal (n); for (int i=2;i<=10000;i++) {if (factor_num[i]&1==0) {ans+=cal (count[i]);} Else{ans-=cal (Count[i]);}} Cout<<ans<<endl;} return 0;}
poj3904 Sky Code