【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 ...
随机推荐
- hive笔记之row_number、rank、dense_rank
hive中有三个与分组排序相关的分析函数(我起初也认为是窗口函数,后来看到手册里是把他们划到了Analytics functions下),row_number.rank.dense_rank,我一直傻 ...
- hdu 确定比赛名次(拓扑排序)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1285 确定比赛名次 Time Limit: 2000/1000 MS (Java/Others) ...
- VMware虚拟机 安装centos7并设置静态ip 连接外网
首先下载VMware虚拟机:http://xzc.197746.com/VMware-Workstation-12.5.9.zip 然后下载centos7镜像:http://vault.centos. ...
- 非极大值抑制(NMS,Non-Maximum Suppression)的原理与代码详解
1.NMS的原理 NMS(Non-Maximum Suppression)算法本质是搜索局部极大值,抑制非极大值元素.NMS就是需要根据score矩阵和region的坐标信息,从中找到置信度比较高的b ...
- RobotFramework安装扩展库包Selenium2Library(三)
Robot Framework扩展库包 http://robotframework.org/#libraries 一,自动化测试web端 1,pip安装SeleniumLibrary pip inst ...
- javascript本地缓存方案-- 存储对象和设置过期时间
cz-storage 解决问题 1. 前端js使用localStorage的时候只能存字符串,不能存储对象 cz-storage 可以存储 object undefined number string ...
- 不同Linux机器之间拷贝文件
不同的Linux之间copy文件常用有3种方法: 第一种就是ftp,也就是其中一台Linux安装ftp Server,这样可以另外一台使用ftp的client程序来进行文件的copy. 第二种方法就是 ...
- 洛谷P2015二叉苹果树
传送门啦 树形 $ dp $ 入门题,学树形 $ dp $ 的话,可以考虑先做这个题. $ f[i][j] $ 表示在 $ i $ 这棵子树中选 $ j $ 个苹果的最大价值. include #in ...
- Linux命令之远程登录与执行远程主机命令
实现远程登录的命令 ssh.telnet.rlogin (1)ssh命令 ssh命令是openssh套件中的客户端连接工具,可以给予ssh加密协议实现安全的远程登录服务器.ssh命令用于远程登录上Li ...
- CVE-2010-2883Adobe Reader和Acrobat CoolType.dll栈缓冲区溢出漏洞分析
Adobe Acrobat和Reader都是美国Adobe公司开发的非常流行的PDF文件阅读器. 基于Window和Mac OS X的Adobe Reader和Acrobat 9.4之前的9.x ...