N. Sky Code

Time Limit: 1000ms
Case Time Limit: 1000ms
Memory Limit: 65536KB
 
64-bit integer IO format: %lld      Java class name: Main
Font Size: + -
Stancu likes space travels but he is a poor software developer and will never be able to buy his own spacecraft. That is why he is preparing to steal the spacecraft of Petru. There is only one problem – Petru has locked the spacecraft with a sophisticated cryptosystem based on the ID numbers of the stars from the Milky Way Galaxy. For breaking the system Stancu has to check each subset of four stars such that the only common divisor of their numbers is 1. Nasty, isn’t it? Fortunately, Stancu has succeeded to limit the number of the interesting stars to N but, any way, the possible subsets of four stars can be too many. Help him to find their number and to decide if there is a chance to break the system.

 

Input

In the input file several test cases are 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 is 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 line with the number of subsets with the asked property.

 

Sample Input

4
2 3 4 5
4
2 4 6 8
7
2 3 4 5 7 6 8
 

Sample Output

1
0
34 题意:给10^4个数字,最大数字不超过10^4. 求4元组 gcd(x,y,z,k)=1 ;
思路:莫比乌斯。 统计F【i】的数字的个数。 F(d) = Cnm(F[d],4)种方案。
 #include<iostream>
#include<stdio.h>
#include<cstring>
#include<cstdlib>
using namespace std;
const int N = 1e4+; int vis[N];
int mu[N];
int prime[N],cnt;
int num[N];
int Hash[N]; void init()
{
memset(vis,,sizeof(vis));
mu[] = ;
cnt = ;
for(int i=;i<N;i++)
{
if(!vis[i])
{
prime[cnt++] = i;
mu[i] = -;
}
for(int j = ;j<cnt&&i*prime[j]<N;j++)
{
vis[i*prime[j]] = ;
if(i%prime[j]) mu[i*prime[j]] = -mu[i];
else
{
mu [i *prime[j]] = ;
break;
}
}
}
}
long long Cnm(int n,int m)
{
if(n<m)return ;
long long nn=n;
long long mm=m;
long long i,j;
long long sum = ;
for(i=,j=nn;i<=mm;i++,j--)
sum = sum *j/i;
return sum;
}
int main()
{
int n,x;
init();
while(scanf("%d",&n)>)
{
memset(num,,sizeof(num));
memset(Hash,,sizeof(Hash));
int maxn = ;
for(int i=;i<=n;i++){
scanf("%d",&x);
Hash[x]++;
if(x>maxn) maxn=x;
}
for(int i=;i<=maxn;i++)
{
for(int j=i;j<=maxn;j=j+i)
num[i]=num[i]+Hash[j];
}
long long sum = ;
for(int i=;i<=maxn;i++){
long long tmp = Cnm(num[i],);
sum = sum+tmp*mu[i];
}
printf("%I64d\n",sum);
}
return ;
}

POJ Sky Code 莫比乌斯反演的更多相关文章

  1. POJ3094 Sky Code(莫比乌斯反演)

    POJ3094 Sky Code(莫比乌斯反演) Sky Code 题意 给你\(n\le 10^5\)个数,这些数\(\le 10^5\),问这些这些数组成的互不相同的无序四元组(a,b,c,d)使 ...

  2. POJ 3904 JZYZOJ 1202 Sky Code 莫比乌斯反演 组合数

    http://poj.org/problem?id=3904   题意:给一些数,求在这些数中找出四个数互质的方案数.   莫比乌斯反演的式子有两种形式http://blog.csdn.net/out ...

  3. hdu.5212.Code(莫比乌斯反演 && 埃氏筛)

    Code Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submi ...

  4. HDU 5212 Code (莫比乌斯反演)

    题意:给定上一个数组,求 析: 其中,f(d)表示的是gcd==d的个数,然后用莫比乌斯反演即可求得,len[i]表示能整队 i 的个数,可以线性筛选得到, 代码如下: #pragma comment ...

  5. poj 3904(莫比乌斯反演)

    POJ 3904 题意: 从n个数中选择4个数使他们的GCD = 1,求总共有多少种方法 Sample Input 4 2 3 4 5 4 2 4 6 8 7 2 3 4 5 7 6 8 Sample ...

  6. POJ 3904 Sky Code (容斥原理)

    B - Sky Code Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit ...

  7. POJ 3904 (莫比乌斯反演)

    Stancu likes space travels but he is a poor software developer and will never be able to buy his own ...

  8. 【BZOJ-2440】完全平方数 容斥原理 + 线性筛莫比乌斯反演函数 + 二分判定

    2440: [中山市选2011]完全平方数 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 2371  Solved: 1143[Submit][Sta ...

  9. 【BZOJ-4407】于神之怒加强版 莫比乌斯反演 + 线性筛

    4407: 于神之怒加强版 Time Limit: 80 Sec  Memory Limit: 512 MBSubmit: 241  Solved: 119[Submit][Status][Discu ...

随机推荐

  1. Codeforce Round #228 Div2

    这次的A题没注意要到100- -, B题没做,后来做要注意下1和long long C题当时坑的一B,用了个蠢办法,后来还错了,现在改了,还是蠢办法,等等再去用dp吧,而且本来就只有01用个鸡巴的树状 ...

  2. Fzu oj2194星系碰撞(排序+并查集+路径压缩)

    Problem 2194 星系碰撞 Accept: 14    Submit: 48Time Limit: 30000 mSec    Memory Limit : 327680 KB  Proble ...

  3. [转]30分钟学会反向Ajax

    原文链接:http://www.cnblogs.com/learnhow/p/5708364.html 场景1:当有新邮件的时候,网页自动弹出提示信息而无需用户手动的刷新收件箱. 场景2:当用户的手机 ...

  4. HTML5 Canvas arc()函数

    实例 创建一个圆形: var c=document.getElementById("myCanvas"); var ctx=c.getContext("2d") ...

  5. 生成apache证书(https应用)

    # cd /usr/local/apache2/conf# tar zxvf ssl.ca-0.1.tar.gz# cd ssl.ca-0.1生成根证书:# ./new-root-ca.sh      ...

  6. Windows 2003/2008更改远程桌面端口脚本

    保存为bat文件,点击运行按提示输入新端口自动完成,直接下载更改远程桌面端口脚本   @echo off color 0a title @@ 修改Windows XP/2003/2008远程桌面服务端 ...

  7. Workflow Mailer Notifications设置

    参考:http://www.docin.com/p-651716490.html http://www.360doc.com/content/12/0218/15/3200886_187602886. ...

  8. yii2.0分页

    本实例是对商品列表进行分页 1.Controller中,商品列表的方法actionList 引用分页类 actionList中: $goods_info=Goods::find()->joinW ...

  9. BPM 应用系统开发案例实战

    概述 IBM BPM 的前身是 Lombardi,是由 IBM 于 2009 年收购的产品,之后产品更名为 IBM WebSphere Lombardi Edition,目前最新版本称为 IBM BP ...

  10. empty()、html("")和text("")

    empty().html("")和text("")在删除匹配元素内内容时是一样的.jQuery源码中实现有所不同,但效果相同.可以测试一下源码: <!DO ...