vijos P1629八 容斥原理
注意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八 容斥原理的更多相关文章
- P1629八
P1629八 Accepted 标签:[显示标签] 描述 八是个很有趣的数字啊.八=发,八八=爸爸,88=拜拜.当然最有趣的还是8用二进制表示是1000.怎么样,有趣吧.当然题目和这些都没有关 ...
- Vijos 1360 - 八数码问题 - [A*]
题目链接:https://vijos.org/p/1360 优先队列BFS: 这个八数码问题本身其实是之前人工智能实验课的作业…… 首先,如果不带估价函数,直接用优先队列BFS,肯定也是能得到正确结果 ...
- vijos 1360 八数码问题 - 启发式搜索
背景 Yours和zero在研究A*启发式算法.拿到一道经典的A*问题,但是他们不会做,请你帮他们. 描述 在3×3的棋盘上,摆有八个棋子,每个棋子上标有1至8的某一数字.棋盘中留有一个空格,空格用0 ...
- 【宽搜】Vijos P1360 八数码问题
题目链接: https://vijos.org/p/1360 题目大意: 3x3格子上放1~8数字,一个空位,每次空位可与上下左右交换,固定终止布局,求输入的起始布局需要几步到达终止布局 题目思路: ...
- Cogs 513. 八(容斥原理)
八 ★☆ 输入文件:eight.in 输出文件:eight.out 简单对比 时间限制:1 s 内存限制:128 MB [问题描述] 八是个很有趣的数字啊.八=发,八八=爸爸,88=拜拜.当然最有趣的 ...
- 【vijos】1629 八(容斥原理+dfs)
https://vijos.org/p/1629 本来是想出来了的,,,,但是有个地方写挫了一直没发现,sad 就是dfs的时候我传的pos传错了QAQ 这题用容斥很好想 首先在区间[l, r]能被a ...
- Vijos——T 1629 八
https://vijos.org/p/1629 描述 八是个很有趣的数字啊.八=发,八八=爸爸,88=拜拜.当然最有趣的还是8用二进制表示是1000.怎么样,有趣吧.当然题目和这些都没有关系. 某个 ...
- VIJOS 1889 天真的因数分解(莫比乌斯反演,容斥原理)
https://vijos.org/p/1889 同BZOJ2440..,不过这题要求的是有因数因子的,所以莫比乌斯函数要稍微改一下 #include<algorithm> #includ ...
- HDU5838 Mountain(状压DP + 容斥原理)
题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5838 Description Zhu found a map which is a N∗M ...
随机推荐
- coco2d-x怎样创建project
不知道coco2d-x从那个版本号開始用python创建project,一句话搞定,确实省去了好多麻烦. 首先定位到coco2d-x的文件夹到cocos2d-x-2.2.3\cocos2d-x-2.2 ...
- random模块的使用
random模块用于生成随机数 import random print random.random() #用于生成小于1大于0的数 print random.randint(1,5) #生成大于等于1 ...
- 【转载】TCP和TCP/IP的区别
TCP/IP协议(Transmission Control Protocol/Internet Protocol)叫做传输控制/网际协议, 又叫网络通讯协议,这个协议是Internet国际互联网络的基 ...
- POST 请求静态文件 响应405
使用post方式请求js.html这样的静态文件一般的web服务器都会返回405 Method Not Allowed. 我测试用的web服务器用的是IIS(windows10+IIS10),理论上来 ...
- 2016/05/16 UEditor 文本编辑器 使用教程与使用方法
第一:百度UEditor编辑器的官方下载地址 ueditor 官方地址:http://ueditor.baidu.com/website/index.html 开发文档地址:http://uedito ...
- 2016/3/30 租房子 ①建立租房子的增、删、改php页面 ②多条件查询 ③全选时 各部分全选中 任意checkbox不选中 全选checkbox不选中
字符串的另一种写法:<<<AAAA; 后两个AA回车要求顶格 不然报错 例子: <!DOCTYPE html> <html lang="en" ...
- Django的各种初识
1,django项目的各个文件的介绍 1.1>项目的根目录:是各个子文件的根目录,在各个文件相互导入文件的时候使用 1.2>配置文件:为django的各个文件配置相关的各种默认配置 1.3 ...
- arm位清零bic指令
(1)指令的语法格式 BIC{<cond>}{S} <Rd>,<Rn>,<shifter_operand> BIC(Bit Clear)位清零指令,将寄 ...
- javascript正则找script标签, link标签里面的src或者 href属性
1. [代码]javascript 简单的search <script(?:(?:\s|.)+?)src=[\"\'](.+?)[\"\'](?!\<)(?:(? ...
- Mac 中安装 Apache Ant
1.下载Apache Ant:http://ant.apache.org/bindownload.cgi 2.解压apache-ant-1.9.6-bin.zip,把解压好的apache-ant-1. ...