【题目链接】:http://acm.uestc.edu.cn/#/problem/show/1544

【题意】

【题解】



容斥原理题;

1..(2^m)-1枚举

设k为其二进制形式中1的个数;

k为奇数

ans+=2^(k-1)*(n/lcm(对应的k个数))

否则-=…..

如果不加那个系数的话,算的是这几个数的公倍数的个数…



【Number Of WA】



2



【反思】



没有注意到自己做的结果是什么…



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define Open() freopen("F:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0) typedef pair<int, int> pii;
typedef pair<LL, LL> pll; const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
const double pi = acos(-1.0);
const int N = 15; int n, m;
int a[N + 5];
int two[N + 5]; LL gcd(LL x, LL y) {
return y == 0 ? x : gcd(y, x%y);
} LL lcm(LL x, LL y) {
return (x / gcd(x, y)*y);
} void solve() {
cin >> n >> m;
rep1(i, 1, m)
cin >> a[i];
LL ans = 0;
rep1(i, 1, two[m] - 1) {
int num = 0; LL temp = 1;
rep1(j, 1, m)
if (i&(two[j-1])){
num++;
if (temp > n) continue;
temp = lcm(temp, a[j]);
}
if (num & 1)
ans += two[num-1]*(n / temp);
else
ans -= two[num-1]*(n / temp);
}
cout << ans << endl;
} int main() {
//Open();
Close();
two[0] = 1;
rep1(i, 1, 15) two[i] = two[i - 1] * 2;
int T;
cin >> T;
while (T--) {
solve();
}
return 0;
}

最新文章

  1. js运动框架之一条乱跑的虫子
  2. ubuntu gcc-5 安装
  3. Java中的TreeMap、Comparable、Comparator
  4. django中时区设置
  5. Oracle 12c 数据库中scott用户不存在的解决方法
  6. Oracle 联合主键
  7. OpenCV之mixChannels()函数使用说明
  8. linux下启动和关闭网卡命令
  9. 解决animate动画连续播放bug
  10. 二探ListView
  11. 6. Shell 流程控制
  12. R与并行计算(转)
  13. Even Parity uva11464 模拟
  14. IdentityServer4 实现 OAuth 2.0(密码模式 - HTTP Post 方式)
  15. javascript第三章--引用类型
  16. 《java入门第一季》正则表达式小案例
  17. Linux中断管理 (1)Linux中断管理机制
  18. js jquery 遍历 for,while,each,map,grep
  19. opencv+python-图片文本倾斜校正
  20. Javascript-关于break、continue、return语句

热门文章

  1. Sublime Text 3 注册码 激活码 版本号 Build 3143
  2. XML学习(一)——xml内容简介
  3. HTML基础——网站首页显示页面
  4. 使用xshell连接本地虚拟机中的Linux问题
  5. shell-1.shell概述、2.shell脚本执行方式
  6. CorelDRAW X6低价再次冲破底线
  7. NOIp模拟赛二十八
  8. WPF内嵌WCF服务对外提供接口
  9. 【转载】CPU架构、指令集与指令集体系结构(ISA)
  10. 最多包含2/k个不同字符的最长串