博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【CF 585E】 E. Present for Vitalik the Philatelist
阅读量:4467 次
发布时间:2019-06-08

本文共 3628 字,大约阅读时间需要 12 分钟。

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没算,应该会快一点把【反正过了

 

1 #include
2 #include
3 #include
4 #include
5 #include
6 using namespace std; 7 #define Maxn 500010 8 #define Maxm 10001000 9 #define Mod 100000000710 11 int mu[Maxm],pri[Maxm],pl,mx;12 int cnt[Maxm],pw[Maxn],a[Maxn];13 bool vis[Maxm];14 void init()15 {16 memset(vis,0,sizeof(vis));17 for(int i=2;i<=mx;i++)18 {19 if(!vis[i]) pri[++pl]=i,mu[i]=-1;20 for(int j=1;j<=pl;j++)21 {22 if(pri[j]*i>mx) break;23 vis[pri[j]*i]=1;24 if(i%pri[j]==0) mu[i*pri[j]]=0;25 else mu[i*pri[j]]=-mu[i];26 if(i%pri[j]==0) break;27 }28 }29 }30 31 int main()32 {33 int n;34 scanf("%d",&n);mx=0;35 memset(cnt,0,sizeof(cnt));36 for(int i=1;i<=n;i++) {scanf("%d",&a[i]);mx=max(mx,a[i]);cnt[a[i]]++;}37 init();38 pw[0]=1;for(int i=1;i<=n;i++) pw[i]=(pw[i-1]*2)%Mod;39 int ans=0;40 for(int i=2;i<=mx;i++) if(mu[i]!=0)41 {42 int nw=0;43 for(int j=i;j<=mx;j+=i) nw+=cnt[j];44 ans=(ans+1LL*(pw[nw]-1)*(-mu[i])*(n-nw)%Mod)%Mod;45 }46 ans=(ans+Mod)%Mod;47 printf("%d\n",ans);48 return 0;49 }
View Code

 

2017-04-20 19:16:41

转载于:https://www.cnblogs.com/Konjakmoyu/p/6740369.html

你可能感兴趣的文章
Python 爬虫插件
查看>>
【BZOJ-3809】Gty的二逼妹子序列 分块 + 莫队算法
查看>>
k8s-调度器、预选策略及优选函数-二十
查看>>
Noip 2011 Day 1 & Day 2
查看>>
一些有用的资源分享(工具+电子书)
查看>>
虚拟现实-ar one
查看>>
python接口自动化测试二十五:执行所有用例,并生成HTML测试报告
查看>>
c# 指定的存储区提供程序在配置中找不到,或者无效
查看>>
最简陋的python数据
查看>>
第一堂java web课
查看>>
操作系统简介
查看>>
第1周小组博客作业--1703班06组
查看>>
vue项目中icon图标的完美引入
查看>>
C语言指针
查看>>
Java的安装
查看>>
0920 JSON数据 蓝懿
查看>>
Azure Cosmos DB 使用费用参考
查看>>
【嵌入式开发】写入开发板Linux系统-模型S3C6410
查看>>
C# 子线程与主线程通讯方法一
查看>>
006——修改tomacat的编码
查看>>