【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 ...
随机推荐
- 关于数据区间变换及numpy数组转图片数据的python实现
python实现区间转换.numpy图片数据转换 需求: 客户的需求是永无止境的,这不?前几天,用户提出了一个需求,需要将一组数据从一个区间缩放到另一区间? 思路: 先将数据归一化,再乘以对应区间的差 ...
- Celery异步任务队列/周期任务+ RabbitMQ + Django
一.Celery介绍和基本使用 Celery 是一个 基于python开发的分布式异步消息任务队列,通过它可以轻松的实现任务的异步处理, 如果你的业务场景中需要用到异步任务,就可以考虑使用celer ...
- nginx+tomat https ssl 部署 完美解决方案
关于nginx+tomcat https的部署之前网上一直有2种说法: 1.nginx和tomcat都要部署ssl证书 2.nginx部署ssl证书,tomcat增加ssl支持 在实际的部署过程中ng ...
- 解决eclipse Debug时提示source not found的问题
解决办法: 选择Change Attached Source,添加自己的project,clean项目,重启eclipse即可.
- ExtJs的Reader
ExtJs的Reader Reader : 主要用于将proxy数据代理读取的数据按照不同的规则进行解析,讲解析好的数据保存到Modle中 结构图 Ext.data.reader.Reader 读取器 ...
- 蛮力法解决0_1背包问题新思路-——利用C语言位域类型
废话不说了,直接上代码 #include<stdio.h> #include<math.h> #define N 5 //物品种类数目 #define CAPACITY 6 / ...
- SQL SERVER2008 存储过程、表、视图、函数的权限
EXEC sp_addrolemember N'db_owner', N'db'----将db 设置为 db_owner 角色中的一员 EXEC sp_droprolemember N'db_owne ...
- SQL SERVER 触发器介绍
什么是触发器 触发器对表进行插入.更新.删除的时候会自动执行的特殊存储过程.触发器一般用在check约束更加复杂的约束上面.触发器和普通的存储过程的区别是:触发器是当对某一个表进行操作.诸如:upda ...
- WeifenLuo.WinFormsUI.Docking"的使用
要用 WeifenLuo.WinFormsUI.Docking 首先要下载: WeifenLuo.WinFormsUI.Docking 在当前工程“解决方案 - 引用”中 >> 右击引用 ...
- OneNote无法同时设置中英文字体设置解决办法
如果你是一位OneNote老用户,无论是2003.2007还是2010或者最新的2013版本,都一直存在一个Bug,就是无法同时设置中英文字体(比如在Word中就可以分别设置不同的).我搜了一下,在微 ...