SSL2776 2017年10月19日提高组 整除(容斥+dfs)
来源:互联网 发布:拉尼娅王后知乎 编辑:程序博客网 时间:2024/05/16 09:30
2017年10月19日提高组 整除
Description
给出n个数a1,a2……an,求区间[L,R]中有多少个整数不能被其中任何一个数整除。
Input
第一行三个正整数,n,L,R。
第二行n个正整数a1,a2……an
Output
一个数,即区间[L,R]中有多少个整数不能被其中任何一个数整除。
分析:容斥原理。
代码
#include <cstdio>#define maxn 20#define ll long longusing namespace std;int a[maxn],n,l,r;ll ans;ll gcd(ll x,ll y){ return y==0?x:gcd(y,x%y);}ll lcm(ll x,ll y){ return (ll)x*(ll)y/(ll)gcd(x,y);}void dfs(int dep,int x,ll lc){ if (dep>n) { if (x%2==1) ans-=(ll)r/lc-(ll)(l-1)/lc; else ans+=(ll)r/lc-(ll)(l-1)/lc; return; } dfs(dep+1,x+1,lcm(lc,a[dep])); dfs(dep+1,x,lc);}int main(){ scanf("%d%d%d",&n,&l,&r); for (int i=1;i<=n;i++) scanf("%d",&a[i]); dfs(1,0,1); printf("%lld",ans);}
阅读全文
0 0
- SSL2776 2017年10月19日提高组 整除(容斥+dfs)
- 【SSLGZ 2776】2017年10月19日提高组 整除(number)(容斥原理)
- SSL2787 2017年10月24日提高组 一个不成熟的想法(dfs)
- SSL2675 2017年8月9日提高组T3 难题(dfs)
- SSL2682 2017年8月12日提高组T1 YMW的杯子(dfs)
- SSL2703 2017年8月16日提高组T2 疾病(dfs)
- SSL2836 2017年11月4日提高组T2 序列(迭代dfs)
- SSL2775 2017年10月19日提高组 新壳栈
- SSL2668 2017年8月7日提高组T1 根(dfs)
- SSL2669 2017年8月7日提高组T1 选数(dfs)
- SSL2774 2017年10月19日提高组 青蛙(math)
- 2017年8月10日提高组T1 数学
- 2017年8月10日提高组T1 数学
- 2017年8月10日提高组T1 数学
- 2017年10月6日提高组T2 挖矿
- 2017年10月6日提高组T2 挖矿
- 2017年10月7日提高组T1 染色
- 2017年10月23日提高组T3 询问
- Android LockSupport 分析
- BZOJ 1051 [HAOI2006]受欢迎的牛
- K-means++算法思想
- TP5上传图片Call to a member function move() on null
- GoldenGate(4)_问题答疑与部署中的错误记录
- SSL2776 2017年10月19日提高组 整除(容斥+dfs)
- C++实现string类
- bzoj 3173: [Tjoi2013]最长上升子序列
- JavaScript综述
- 2017-10-19-Mysql 常用函数
- idea中关闭当前文件快捷键
- 转《阿里巴巴Java开发规约》插件使用详细指南
- linux zookeeper 安装
- Android greenDao数据库的简单使用(一)