莫比乌斯+容斥 cf803F
来源:互联网 发布:带网络功能的winpe 编辑:程序博客网 时间:2024/06/05 04:16
F. Coprime Subsequences
time limit per test
2 secondsmemory limit per test
256 megabytesinput
standard inputoutput
standard outputLet's call a non-empty sequence of positive integers a1, a2...akcoprime if the greatest common divisor of all elements of this sequence is equal to1.
Given an array a consisting of n positive integers, find the number of its coprime subsequences. Since the answer may be very large, print it modulo 109 + 7.
Note that two subsequences are considered different if chosen indices are different. For example, in the array[1, 1] there are3 different subsequences:[1],[1] and [1, 1].
Input
The first line contains one integer number n (1 ≤ n ≤ 100000).
The second line contains n integer numbersa1, a2...an (1 ≤ ai ≤ 100000).
Output
Print the number of coprime subsequences ofa modulo109 + 7.
Examples
Input
31 2 3
Output
5
Input
41 1 1 1
Output
15
Input
71 3 5 15 3 105 35
Output
100
定义f(i) 为以 i 为 gcd 的序列数,初始化f(i)=2c(i)−1 ,c(i) 是以 i 为因子的数的个数。
直接加起来肯定有重复的部分,所以从后往前筛f(i)=f(i)−∑i|df(d) 即可。
100
定义
直接加起来肯定有重复的部分,所以从后往前筛
#include<stdio.h>#include<stdlib.h>#include<string.h>#include<math.h>#include<iostream>#include<algorithm>#include<stack>#include<queue>#include<vector>#include<set>#include<map>#include<string>using namespace std;typedef long long ll;const int INF=0x3f3f3f3f;const ll mod=1e9+7;const double eps=1e-9;ll bit[100010];ll ans[100010];int num[100010];void init(){ bit[0]=1; for(int i=1;i<=100003;i++) bit[i]=(bit[i-1]*2)%mod;}int main(){ init(); int n,x,maxx=-1; scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%d",&x); num[x]++; maxx=max(maxx,x); } for(int i=maxx;i>0;i--) { int sum=0; for(int j=i;j<=maxx;j+=i) { sum+=num[j]; ans[i]=(ans[i]-ans[j]+mod)%mod; } ans[i]=(ans[i]+bit[sum]-1)%mod; } printf("%lld\n",ans[1]); return 0;}
阅读全文
1 0
- 莫比乌斯+容斥 cf803F
- hdu 5212 code 容斥~或者莫比乌斯
- BZOJ2440 莫比乌斯反演 + 二分+ 容斥
- hdu5468 Puzzled Elena(容斥 莫比乌斯反演)
- [容斥+莫比乌斯]bzoj2440_完全平方数
- 【HDU1695】GCD(莫比乌斯反演+容斥)
- bzoj 2301 莫比乌斯反演+容斥原理
- HDU 1695 GCD 莫比乌斯,容斥原理
- BZOJ2301 容斥原理,莫比乌斯反演
- codeforces803F Coprime Subsequences -- 莫比乌斯函数+容斥
- ural1091(莫比乌斯 容斥)
- hdu 6053 莫比乌斯函数(容斥)
- hdu 6053 TrickGCD 容斥 莫比乌斯
- HDU6053-TrickGCD 容斥原理+莫比乌斯反演
- hdu 6053 TrickGCD 【容斥&筛法|莫比乌斯】
- hdu 6053 (莫比乌斯反演+容斥)
- HDU6053(莫比乌斯函数+容斥定理)
- hdu6053 TrickGCD 莫比乌斯函数 容斥原理
- Android Studio中手机能连接上ADB不过一直跑不起来(或者应用出现短暂的白屏)
- linux
- Servlet中的构造函数与init()方法
- 利用ssh传输文件
- java生成wsdl的客户端代码
- 莫比乌斯+容斥 cf803F
- Valid_Parentheses
- macOS Sierra 设置ipv6热点(无法创建NA64网络问题)
- python3爬虫之入门和正则表达式
- Linux-gcc编程
- 构建基于分布式SOA架构的统一身份认证体系
- 基于gensim进行句向量的训练
- R-CNN论文详解
- Java IO