【codeforces 803F】Coprime Subsequences
【题目链接】:http://codeforces.com/contest/803/problem/F
【题意】
给你一个序列;
问你这个序列里面有多少个子列;
且这个子列里面的所有数字互质;
【题解】
计算cnt[x];
表示数组里有多少个数是x的倍数;
则某个子列里面所有的数字都能被x整除的子列个数为2cnt[x]−1
把这个值记为f[x];
则我们用需要用容斥原理;
把所有能被2,3,..n整除的子列删除掉;
这里面会有重复计数的问题;
解决方式是,从大到小枚举f[x]
然后对于y=i*x的
f[x]减去所有的f[y];
这样就能保证
在减掉
f[2]的时候,不会包括f[4]的方案;
最后剩下的就是互质的子列方案了;
f[x]在逆序更新过后;
实际上是gcd为x的子列的个数;
减去x的倍数的gcd;是为了减去那些gcd不为x的子列;
因为对于【全是x的倍数】的倍数的子列;它们的gcd并不为x;
UPD1:
写得更形式一点
f[i]=f[i]−∑i|xf[x]
即逆着筛掉gcd不为i的子列;
【Number Of WA】
0
【完整代码】
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 1e5+100;
const LL MOD = 1e9+7;
int bo[N],n,f[N],ma;
LL po[N];
int main()
{
//freopen("F:\\rush.txt","r",stdin);
ios::sync_with_stdio(false),cin.tie(0);//scanf,puts,printf not use
cin >> n;
po[0] = 1;
rep1(i,1,n)
po[i] = (1LL*po[i-1]*2)%MOD;
rep1(i,1,n)
{
int x;
cin >> x;
ma = max(ma,x);
bo[x]++;
}
rep1(i,1,ma)
{
int ret = 0;
for (int j = i;j<=ma;j+=i)
ret+=bo[j];
f[i] = po[ret]-1;
}
rep2(i,ma,1)
for (int j = i+i;j<=ma;j+=i)
f[i] = (f[i]-f[j]+MOD)%MOD;
cout << f[1] << endl;
return 0;
}
【codeforces 803F】Coprime Subsequences的更多相关文章
- CodeForces - 803F: Coprime Subsequences(莫比乌斯&容斥)
Let's call a non-empty sequence of positive integers a1, a2... ak coprime if the greatest common div ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【codeforces 314C】Sereja and Subsequences
[题目链接]:http://codeforces.com/problemset/problem/314/C [题意] 让你从n个元素的数组中选出所有的不同的非递减子数列; 然后计算比这个子数列小的和它 ...
- 【codeforces 766A】Mahmoud and Longest Uncommon Subsequence
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
- 【codeforces 709B】Checkpoints
[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...
- 【codeforces 709C】Letters Cyclic Shift
[题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...
随机推荐
- HDU 1429--胜利大逃亡(续)【BFS && 状态压缩】
胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
- IOS - 查找未使用的图片
实现细节都在代码里面, 帮助 -h. # -*- coding: utf-8 -*- """ 检查IOS应用图片是否使用 1. 读取有效文件: 图片(.png, .jpg ...
- ioctl方法详解
设备控制接口(ioctl 函数)回想一下我们在字符设备驱动中介绍的struct file_operations 结构,这里我们将介绍一个新的方法: int (*ioctl) (struct inode ...
- 框架-Java:Spring Cloud
ylbtech-框架-Java:Spring Cloud Spring Cloud是一系列框架的有序集合.它利用Spring Boot的开发便利性巧妙地简化了分布式系统基础设施的开发,如服务发现注册. ...
- day63-webservice 06.在web项目中发布以类的形式发布webservice
真正用的时候都是需要部署在WEB服务器里面. 不能写主函数来发布了,需要借助于我们WEB. 4.配置web.xml, <!DOCTYPE web-app PUBLIC "-//Sun ...
- POJ 2337 欧拉回路
题意: 如果给出的单词能够首尾相接,请按字典序输出单词,中间要加'.' 否则输出三个"*". 思路: 欧拉回路 记得按字典序排序哦~ 加边的时候要倒着加.(邻接表遍历的时候是反着的 ...
- C - Twins(贪心)
Problem description Imagine that you have a twin brother or sister. Having another person that looks ...
- pinpoint体系中,关于如何清理过期hbase数据
版本: pinpoint:1.7.1 hbase:1.2.6 命令行命令: $HBASE_HOME/bin/hbase shell newrestruct.hbase 备注:保留一天半的数据(秒 ...
- Monad的重点
Monad是非常强有力的概念,在介绍Monad是什么和如何工作的之前,我们应该先确认Monad能解决什么问题.Monad是各种编程问题的的 meta solution,它不是某种特定问题的解决方案,我 ...
- vue-cli3+typescript+router
vue基于类的写法,和基于对象的写法并不一致.使用vue-cli3创建的项目,src目录下的文件结构并没有多大区别,store.router.app.view.components.aeests该有的 ...