vijos P1629八 容斥原理
2024-09-04 21:40:13
注意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 ;
}
最新文章
- mysql 删除时候有外键提示问题解决
- C#,java,C++ 等变量命名规则
- GIF录制神器GifCam
- Android之activity初讲
- git入门-分支
- a标签href不跳转 禁止跳转
- sqlserver 脚本方式导出数据到excel
- H2Engine游戏服务器设计之属性管理器
- kafka和mqtt的区别是什么?
- MyBatis系列目录--5. MyBatis一级缓存和二级缓存(redis实现)
- java网页爬数据获取class中的空格
- DAY 17常用模块
- 3D轮播图
- H5的简介
- SpringMVC由浅入深day01_12.4 pojo绑定_12.5自定义参数绑定实现日期类型绑定_12.6集合类
- React 组件的生命周期API和事件处理
- Linux环境下安装配置Mysql
- 【Android】8.1 主题基本用法
- thinkphp,下载附件
- 转-使用wifi调试程序