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. Maven教程(转载)

    转载自:http://www.yiibai.com/maven/ Apache Maven是一个软件项目管理和综合工具.基于项目对象模型(POM)的概念,Maven可以从一个中心资料片管理项目构建,报 ...

  2. [转]MySQL数据库引擎

    经常用MySQL数据库,但是,你在用的时候注意过没有,数据库的存储引擎,可能有注意但是并不清楚什么意思,可能根本没注意过这个问题,使用了默认的数据库引擎,当然我之前属于后者,后来成了前者,然后就有了这 ...

  3. javascript浏览器对象

    window对象 1.window对象 window对象是BOM的核心,window对象指当前的浏览器窗口 所有JS全局对象.函数以及变量均自动成为window对象的成员 全局变量是window对象的 ...

  4. C++之路起航——标准模板库(queue)

    queue: FIFO队列:先进先出队列. 优先队列:对队列中的元素按优先级的大小输出. 定义: FIFO队列: queue<数据类性>变量名. 优先队列:priority_queue&l ...

  5. HDU 4834 JZP Set(数论+递推)(2014年百度之星程序设计大赛 - 初赛(第二轮))

    Problem Description 一个{1, ..., n}的子集S被称为JZP集,当且仅当对于任意S中的两个数x,y,若(x+y)/2为整数,那么(x+y)/2也属于S.例如,n=3,S={1 ...

  6. 。。。Hibernate中mappedBy属性。。。

    今天在学习Hibernate中,感觉这个mappedBy这个注解属性有点小难度.不过理解之后,还是阔以的! 首先,mappedBy这个注解只能够用在@OntToOne,@OneToMany,@many ...

  7. 如何学习c++

    在之后的随笔中,我作为一个c++的初学者将会把我如何学习c++的经历尽可能详细的记录下来. 这里引用了JerryZhang在他的博文里面写的一段话,当作我的座右铭. 1.多交流:不管你的技术多么硬,你 ...

  8. 随讲MyIsam和InnoDB的区别

    mysiam表不支持事务处理,同时mysiam表不支持外键.外键不用说了吧?不知道的话,找度娘. 同时,在执行数据库写入的操作(insert,update,delete)的时候,mysiam表会锁表, ...

  9. android 学习随笔十三(网络:多线程下载)

    多线程断点续传下载1.多线程:快* 原理:抢占服务器资源* 单线程下载:线程从第0个字节开始下,下到最后一个字节,在本地硬盘的临时文件中从第0个字节开始写,写到最后一个字节,下载完成时,临时文件也写完 ...

  10. mysql笔记05 优化服务器设置

    优化服务器设置 1. MySQL有大量可以修改的参数--但不应该随便去修改.通常只需要把基本的项配置正确(大部分情况下只有很少一些参数时真正重要的),应将更多时间花在schema的优化.索引,以及查询 ...