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 ;
}

最新文章

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

热门文章

  1. Linux文件系统与磁盘管理
  2. 我的gulp.js清单
  3. 关于 iOS 的 StoryBoard,接受的那一刻才发现她的美 - 当然美的事物都须要业心照料
  4. java8--多线程(java疯狂讲义3复习笔记)
  5. String的属性和方法
  6. Android 6.0 RK3288 ROM编译详解+命令详解【转】
  7. linux系统无法上外网,路由器可以上网,可以ping通路由器,ping不通外网IP
  8. Ubuntu SDL lib 安装
  9. [Usaco2009 Dec] 过路费
  10. 【TJOI 2014】 上升子序列