【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 ...
随机推荐
- [转]caffe中solver.prototxt参数说明
https://www.cnblogs.com/denny402/p/5074049.html solver算是caffe的核心的核心,它协调着整个模型的运作.caffe程序运行必带的一个参数就是so ...
- 【内核】linux内核启动流程详细分析【转】
转自:http://www.cnblogs.com/lcw/p/3337937.html Linux内核启动流程 arch/arm/kernel/head-armv.S 该文件是内核最先执行的一个文件 ...
- Add custom daemon on Linux System
Ubuntu add custom service(daemon) Task 需要在系统启动的时候自动启动一个服务(后台程序),在系统关闭的时候关闭服务. 比如在部署某个应用之前,需要将某个任务设置成 ...
- C基础 - 终结 Size Balanced Tree
引言 - 初识 Size Balanced Tree 最近在抽细碎的时间看和学习 random 的 randnet 小型网络库. iamrandom/randnet - https://github. ...
- 03.JavaScript简单介绍
一.JavaScript的历史 1992年Nombas开发出C-minus-minus(C--)的嵌入式脚本语言(最初绑定在CEnvi软件中).后将其改名ScriptEase.(客户端执行的语言) N ...
- go语言 documentation
Documentation文档 The Go programming language is an open source project to make programmers more pro ...
- Oracle 函数 “申请通过后,将该表中循环遍历到的所有内容插到另一个表中”
create or replace function mcode_apply_insert_material(p_mca_no VARCHAR2, p_action VARCHAR2, p_wf_no ...
- table中的td等长(不随内容大小变化)
使用的table时候发现td的长度是随着内容的大小而变化的,但是有的时候我们不希望这样.想要td等长可以在 tbale中加上 style=“table-layout:fixed” ...
- asterisk各种报错
1.控制台打印出: Got SIP response "Temporarily Unavailable" back from 210.13.87.110:5060 造成原因:在 ...
- SQL2008关于权限的解释
在SQL2008中我自己创建的一个登录名,可是那个登录名只可以用来登录,对数据库的操作什么都不能,连读取数据库都不可以.因为权限不够,只要把登录名的属性打开点击“服务器角色”,把public和sysa ...