https://vijos.org/p/1629

注意lcm要用LL

先给一个样例

1

2

1 10

思路、其实这题就是问,给定一堆数,要求不能整除其任意一个的数字有多少个。

容辞 + lcm

dfs暴力枚举每一位选还是不选,一共n位。00010101010.

然后奇减偶加

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <assert.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <bitset>
const int maxn = + ;
int a[maxn];
int ans;
int L, R, n;
int did(LL val) {
return (R / val) - ((L - ) / val);
}
LL lcm(LL a, LL b) {
return a / __gcd(a, b) * b;
}
void dfs(LL val, int has, int cur) {
if (val > R) return;
if (cur == n + ) {
if (!has) return;
// cout << val << endl;
if (has & ) {
ans -= did(val);
} else ans += did(val);
return;
} // if (cur > n) return;
dfs(lcm(val, a[cur]), has + , cur + );
dfs(val, has, cur + );
}
void work() {
scanf("%d", &n);
for (int i = ; i <= n; ++i) {
scanf("%d", &a[i]);
a[i] = lcm(a[i], );
// a[i] *= 8;
}
// for (int i = 1; i <= n; ++i) {
// cout << a[i] << " ";
// }
// cout << endl;
scanf("%d%d", &L, &R);
///***debug****
// int ans1 = 0;
// for (int i = L; i <= R; ++i) {
// bool flag = true;
// if (i % 8 != 0) continue;
// for (int j = 1; j <= n; ++j) {
// if (i % a[j] == 0) {
// flag = false;
// break;
// }
// }
// if (flag) ans1++;
// }
// cout << ans1 << endl;
ans = did();
// cout << ans << endl;
dfs(, , );
cout << ans << endl;
} int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
work();
return ;
}

vijos P1629八 容斥原理的更多相关文章

  1. P1629八

    P1629八 Accepted 标签:[显示标签]     描述 八是个很有趣的数字啊.八=发,八八=爸爸,88=拜拜.当然最有趣的还是8用二进制表示是1000.怎么样,有趣吧.当然题目和这些都没有关 ...

  2. Vijos 1360 - 八数码问题 - [A*]

    题目链接:https://vijos.org/p/1360 优先队列BFS: 这个八数码问题本身其实是之前人工智能实验课的作业…… 首先,如果不带估价函数,直接用优先队列BFS,肯定也是能得到正确结果 ...

  3. vijos 1360 八数码问题 - 启发式搜索

    背景 Yours和zero在研究A*启发式算法.拿到一道经典的A*问题,但是他们不会做,请你帮他们. 描述 在3×3的棋盘上,摆有八个棋子,每个棋子上标有1至8的某一数字.棋盘中留有一个空格,空格用0 ...

  4. 【宽搜】Vijos P1360 八数码问题

    题目链接: https://vijos.org/p/1360 题目大意: 3x3格子上放1~8数字,一个空位,每次空位可与上下左右交换,固定终止布局,求输入的起始布局需要几步到达终止布局 题目思路: ...

  5. Cogs 513. 八(容斥原理)

    八 ★☆ 输入文件:eight.in 输出文件:eight.out 简单对比 时间限制:1 s 内存限制:128 MB [问题描述] 八是个很有趣的数字啊.八=发,八八=爸爸,88=拜拜.当然最有趣的 ...

  6. 【vijos】1629 八(容斥原理+dfs)

    https://vijos.org/p/1629 本来是想出来了的,,,,但是有个地方写挫了一直没发现,sad 就是dfs的时候我传的pos传错了QAQ 这题用容斥很好想 首先在区间[l, r]能被a ...

  7. Vijos——T 1629 八

    https://vijos.org/p/1629 描述 八是个很有趣的数字啊.八=发,八八=爸爸,88=拜拜.当然最有趣的还是8用二进制表示是1000.怎么样,有趣吧.当然题目和这些都没有关系. 某个 ...

  8. VIJOS 1889 天真的因数分解(莫比乌斯反演,容斥原理)

    https://vijos.org/p/1889 同BZOJ2440..,不过这题要求的是有因数因子的,所以莫比乌斯函数要稍微改一下 #include<algorithm> #includ ...

  9. HDU5838 Mountain(状压DP + 容斥原理)

    题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5838 Description Zhu found a map which is a N∗M ...

随机推荐

  1. NODE安装N管理出错

    Windows不支持,反正我在Linux上用过,从此脱离Win坑!

  2. 解决SVN Cleanup时遇到错误信息:Cleanup failed to process the following paths:xxxxxxx Previous operation has not finished: run 'cleanup' if it was interrupted Please execute the 'Cleanup' command.

    解决SVN Cleanup时遇到错误信息:Cleanup failed to process the following paths:xxxxxxx Previous operation has no ...

  3. centos7 安装配置openstack-dashboard (官网openstack-juno版)

    感谢朋友支持本博客.欢迎共同探讨交流.因为能力和时间有限.错误之处在所难免.欢迎指正! 假设转载.请保留作者信息. 博客地址:http://blog.csdn.net/qq_21398167 原博文地 ...

  4. ==和equals的差别

    == 和 Equals 的差别 1. == 是一个运算符. 2.Equals则是string对象的方法.能够.(点)出来. 我们比較无非就是这两种 1.基本数据类型比較 2.引用对象比較 1.基本数据 ...

  5. asp.net mvc + javascript导入文件内容

    .近期做的是对现有项目进行重构.WEB FROM改成MVC,其实也算是推倒重来了. 里面有一个导入功能,将文件上传.原先的做法是有一个隐藏的iframe,在这个iframe的页面中设置一个表单form ...

  6. Struts 1 Struts 2

    Key Technologies Primer https://struts.apache.org/primer.html Threads With Struts 1 you were require ...

  7. bzoj2101【Usaco2010 Dec】Treasure Chest 藏宝箱

    2101: [Usaco2010 Dec]Treasure Chest 藏宝箱 Time Limit: 10 Sec  Memory Limit: 64 MB Submit: 418  Solved: ...

  8. YTU 2922: Shape系列-8

    2922: Shape系列-8 时间限制: 1 Sec  内存限制: 128 MB 提交: 172  解决: 99 题目描述 小聪又想借用小强的Shape类了,但是不巧的是小强去考英语四级去了,但是小 ...

  9. 通过Mesos、Docker和Go,使用300行代码创建一个分布式系统

    [摘要]虽然 Docker 和 Mesos 已成为不折不扣的 Buzzwords ,但是对于大部分人来说它们仍然是陌生的,下面我们就一起领略 Mesos .Docker 和 Go 配合带来的强大破坏力 ...

  10. 并不对劲的p3676:小清新数据结构题

    题目大意 有一棵有\(n\)(\(n\leq 2*10^5\))个点的树,要进行\(q\)(\(q\leq 2*10^5\))次操作,每次操作是以下两种中的一种: 1.修改一个点的点权 2.指定一个点 ...