【CF 585E】 E. Present for Vitalik the Philatelist
E. Present for Vitalik the Philatelisttime limit per test5 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Vitalik the philatelist has a birthday today!
As he is a regular customer in a stamp store called 'Robin Bobin', the store management decided to make him a gift.
Vitalik wants to buy one stamp and the store will give him a non-empty set of the remaining stamps, such that the greatest common divisor (GCD) of the price of the stamps they give to him is more than one. If the GCD of prices of the purchased stamp and prices of present stamps set will be equal to 1, then Vitalik will leave the store completely happy.
The store management asks you to count the number of different situations in which Vitalik will leave the store completely happy. Since the required number of situations can be very large, you need to find the remainder of this number modulo 109 + 7. The situations are different if the stamps purchased by Vitalik are different, or if one of the present sets contains a stamp that the other present does not contain.
InputThe first line of the input contains integer n (2 ≤ n ≤ 5·105) — the number of distinct stamps, available for sale in the 'Robin Bobin' store.
The second line contains a sequence of integers a1, a2, ..., an (2 ≤ ai ≤ 107), where ai is the price of the i-th stamp.
OutputPrint a single integer — the remainder of the sought number of situations modulo 109 + 7.
Examplesinput3
2 3 2output5input2
9 6output0NoteIn the first sample the following situations are possible:
- Vitalik buys the 1-st stamp, the store gives him the 2-nd stamp as a present;
- Vitalik buys the 3-rd stamp, the store gives him the 2-nd stamp as a present;
- Vitalik buys the 2-nd stamp, the store gives him the 1-st stamp as a present;
- Vitalik buys the 2-nd stamp, the store gives him the 3-rd stamp as a present;
- Vitalik buys the 2-nd stamp, the store gives him the 1-st and 3-rd stamps as a present.
【题意】
给出一列数,对于每一个数,求选出一个不包含当前数的非空子集满足子集与当前数gcd为1,并且子集中的所有数的gcd不为1的方案数,统计总和。
【分析】
就是说s是一个子集,x是一个数,然后求$\sum gcd(s,x)==1且gcd(s)!=1$
设d=gcd(s),枚举这个d,那就是(2^[d的倍数的个数]-1)*(不是含d因子的数)
但是这样会重复,比如2,3,6在2,3,6时都算了一遍。所以容斥。【你会发现容斥系数是莫比乌斯函数的相反数
【然后mu[i]=0就没有必要算了。时间极限是mlogm,但是mu=0没算,应该会快一点把【反正过了
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define Maxn 500010
#define Maxm 10001000
#define Mod 1000000007 int mu[Maxm],pri[Maxm],pl,mx;
int cnt[Maxm],pw[Maxn],a[Maxn];
bool vis[Maxm];
void init()
{
memset(vis,,sizeof(vis));
for(int i=;i<=mx;i++)
{
if(!vis[i]) pri[++pl]=i,mu[i]=-;
for(int j=;j<=pl;j++)
{
if(pri[j]*i>mx) break;
vis[pri[j]*i]=;
if(i%pri[j]==) mu[i*pri[j]]=;
else mu[i*pri[j]]=-mu[i];
if(i%pri[j]==) break;
}
}
} int main()
{
int n;
scanf("%d",&n);mx=;
memset(cnt,,sizeof(cnt));
for(int i=;i<=n;i++) {scanf("%d",&a[i]);mx=max(mx,a[i]);cnt[a[i]]++;}
init();
pw[]=;for(int i=;i<=n;i++) pw[i]=(pw[i-]*)%Mod;
int ans=;
for(int i=;i<=mx;i++) if(mu[i]!=)
{
int nw=;
for(int j=i;j<=mx;j+=i) nw+=cnt[j];
ans=(ans+1LL*(pw[nw]-)*(-mu[i])*(n-nw)%Mod)%Mod;
}
ans=(ans+Mod)%Mod;
printf("%d\n",ans);
return ;
}
2017-04-20 19:16:41
【CF 585E】 E. Present for Vitalik the Philatelist的更多相关文章
- 【CodeForces】585 E. Present for Vitalik the Philatelist
[题目]E. Present for Vitalik the Philatelist [题意]给定n个数字,定义一种合法方案为选择一个数字Aa,选择另外一些数字Abi,令g=gcd(Ab1...Abx ...
- CF 585 E Present for Vitalik the Philatelist
CF 585 E Present for Vitalik the Philatelist 我们假设 $ f(x) $ 表示与 $ x $ 互质的数的个数,$ s(x) $ 为 gcd 为 $ x $ ...
- CF585E. Present for Vitalik the Philatelist [容斥原理 !]
CF585E. Present for Vitalik the Philatelist 题意:\(n \le 5*10^5\) 数列 \(2 \le a_i \le 10^7\),对于每个数\(a\) ...
- 「CF585E」 Present for Vitalik the Philatelist
「CF585E」 Present for Vitalik the Philatelist 传送门 我们可以考虑枚举 \(S'=S\cup\{x\}\),那么显然有 \(\gcd\{S'\}=1\). ...
- 【CF#338D】GCD Table
[题目描述] 有一张N,M<=10^12的表格,i行j列的元素是gcd(i,j) 读入一个长度不超过10^4,元素不超过10^12的序列a[1..k],问是否在某一行中出现过 [题解] 要保证g ...
- 【CF#303D】Rotatable Number
[题目描述] Bike是一位机智的少年,非常喜欢数学.他受到142857的启发,发明了一种叫做“循环数”的数. 如你所见,142857是一个神奇的数字,因为它的所有循环排列能由它乘以1,2,...,6 ...
- 【35.20%】【CF 706D】Vasiliy's Multiset
time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standa ...
- 【CF 463F】Escape Through Leaf
题意 给你一棵 \(n\) 个点的树,每个节点有两个权值 \(a_i,b_i\). 从一个点 \(u\) 可以跳到以其为根的子树内的任意一点 \(v\)(不能跳到 \(u\) 自己),代价是 \(a_ ...
- 【CF 453A】 A. Little Pony and Expected Maximum(期望、快速幂)
A. Little Pony and Expected Maximum time limit per test 1 second memory limit per test 256 megabytes ...
随机推荐
- Shell基础-通配符
* - 通配符,代表任意字符 ? - 通配符,代表一个字符 # - 注释 | - 分隔两个管线命令的界定 ; - 连续性命令的界定 ~ - 用户的根目录 $ - 变量前需要加的变量值 ! - 逻辑运算 ...
- 2015.07.15——prime素数
prime素数 1.素数也叫质数,定义是一个数只能被1和它自身整除. 素数从2开始,0,1都不是素数. 2.素数的判断(C++) 3.给定某个数,求小于这个数的所有素数 2.素数的判断(C++) bo ...
- 基于NIO的同步非阻塞编程完整案例,客户端发送请求,服务端获取数据并返回给客户端数据,客户端获取返回数据
这块还是挺复杂的,挺难理解,但是多练几遍,多看看研究研究其实也就那样,就是一个Selector轮询的过程,这里想要双向通信,客户端和服务端都需要一个Selector,并一直轮询, 直接贴代码: Ser ...
- word文档下划线无法显示的解决方法
在编辑文档的时候经常会遇到下划线无法显示的情况,如图: 如果遇到不能在姓名后面加下划线的情况,我们该怎么做? 请看下面的图解: 1.首先点击左上角的office图标 2.点击右下角“word选项” 3 ...
- redis从入门到放弃 -> 部署方案
单点部署方案 环境准备: [root@localhost ~]# cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core) [root@ ...
- json在线工具
1.json在线格式化工具 http://www.choujone.com/json/ 2.json在线比较工具 http://tlrobinson.net/projects/javascript-f ...
- YUI Compressor 压缩 JavaScript 原理-《转载》
YUI Compressor 压缩 JavaScript 的内容包括: 移除注释 移除额外的空格 细微优化 标识符替换(Identifier Replacement) YUI Compressor包括 ...
- es6之yield
yield 关键字用来暂停和继续一个生成器函数.我们可以在需要的时候控制函数的运行. yield 关键字使生成器函数暂停执行,并返回跟在它后面的表达式的当前值.与return类似,但是可以使用next ...
- Ubuntu 16.04 使用docker资料汇总与应用docker安装caffe并使用Classifier(ros kinetic+usb_cam+caffe)
Docker是开源的应用容器引擎.若想简单了解一下,可以参考百度百科词条Docker.好像只支持64位系统. Docker官网:https://www.docker.com/ Docker - 从入门 ...
- css边框内凹圆角,解决优惠券的边框问题
关于css边框内凹圆角,找了好久才找到的 <html <head> <title>无标题页</title> <style> body{ backg ...