E. Present for Vitalik the Philatelist
time limit per test

5 seconds

memory limit per test

256 megabytes

input

standard input

output

standard 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.

Input

The 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.

Output

Print a single integer — the remainder of the sought number of situations modulo 109 + 7.

Examples
input
3
2 3 2
output
5
input
2
9 6
output
0
Note

In 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的更多相关文章

  1. 【CodeForces】585 E. Present for Vitalik the Philatelist

    [题目]E. Present for Vitalik the Philatelist [题意]给定n个数字,定义一种合法方案为选择一个数字Aa,选择另外一些数字Abi,令g=gcd(Ab1...Abx ...

  2. CF 585 E Present for Vitalik the Philatelist

    CF 585 E Present for Vitalik the Philatelist 我们假设 $ f(x) $ 表示与 $ x $ 互质的数的个数,$ s(x) $ 为 gcd 为 $ x $ ...

  3. 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\) ...

  4. 「CF585E」 Present for Vitalik the Philatelist

    「CF585E」 Present for Vitalik the Philatelist 传送门 我们可以考虑枚举 \(S'=S\cup\{x\}\),那么显然有 \(\gcd\{S'\}=1\). ...

  5. 【CF#338D】GCD Table

    [题目描述] 有一张N,M<=10^12的表格,i行j列的元素是gcd(i,j) 读入一个长度不超过10^4,元素不超过10^12的序列a[1..k],问是否在某一行中出现过 [题解] 要保证g ...

  6. 【CF#303D】Rotatable Number

    [题目描述] Bike是一位机智的少年,非常喜欢数学.他受到142857的启发,发明了一种叫做“循环数”的数. 如你所见,142857是一个神奇的数字,因为它的所有循环排列能由它乘以1,2,...,6 ...

  7. 【35.20%】【CF 706D】Vasiliy's Multiset

    time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standa ...

  8. 【CF 463F】Escape Through Leaf

    题意 给你一棵 \(n\) 个点的树,每个节点有两个权值 \(a_i,b_i\). 从一个点 \(u\) 可以跳到以其为根的子树内的任意一点 \(v\)(不能跳到 \(u\) 自己),代价是 \(a_ ...

  9. 【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 ...

随机推荐

  1. POJ 1128 Frame Stacking (拓扑排序)

    题目链接 Description Consider the following 5 picture frames placed on an 9 x 8 array. ........ ........ ...

  2. ubuntu安装Android Studio开发环境

    1.下载 https://developer.android.com/studio/ 2.解压文件,将文件夹copy到/opt/ 3.进入/opt/android-studio/bin,运行./stu ...

  3. 解决多个python的兼容问题

    方法1:将(安装路径和scripts)路径添加到系统环境变量,谁的顺序在前面谁就是默认的 方法2:修改python的名字,然后再终端输入比如python2或者python3

  4. 金蝶K3WISE常用数据表

    K3Wise 14.2 清空密码update t_User set FSID=') F ", ,P T #8 *P!D &D 80!N &@ <0 C '+''''+' ...

  5. Sublime2编译Python程序EOFError:EOF when reading a line解决方法【转】

    在Sublime2中编译运行Python文件时,如果代码中包含用户输入的函数时(eg. raw_input()),Ctrl+b编译运行之后会提示以下错误: 解决方法:安装SublimeREPL打开Su ...

  6. linux系统iostat命令详解

    iostat  -k 3 5  (以KB为单位,每3秒统计一次,共统计5次) • avg-cpu: 总体cpu使用情况统计信息,对于多核cpu,这里为所有cpu的平均值    %user    用户空 ...

  7. 根据经纬度坐标计算距离-python

    一.两个坐标之间距离计算 参考链接: python实现 1.Python 根据地址获取经纬度及求距离 2.python利用地图两个点的经纬度计算两点间距离 LBS 球面距离公式 美团app筛选“离我最 ...

  8. docker centos:last 开启sshd 遇到的证书问题

    启动sshd: # /usr/sbin/sshd 一.问题描述 这时报以下错误: [root@ xxx/]# /usr/sbin/sshd Could not load host key: /etc/ ...

  9. jenkins打包安卓项目

    jenkins打包安卓项目和其它项目差不了太多. 1.构建选择 gradle(如果不用gradle自己写脚本编译也可) 2.jenkins用户需要安装JDK.SDK,jenkins会自动下载gradl ...

  10. Spring框架(管理事务)

    Spring底层使用Transaction事物模板来进行操作.具体操作: 1.service 需要获得 TransactionTemplate 2.spring 配置模板,并注入给service 3. ...