题目链接:https://www.luogu.org/problemnew/show/SP6285

唉好久之前校内模拟赛的题目

嘴上说着明白但是实现起来我的位运算太丑陋了啊!

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;
const int maxn = 300;
ll n, k, a[maxn], ans;
ll gcd(ll x, ll y)
{
if(x % y == 0) return y;
else return gcd(y, x%y);
}
ll lcm(ll x, ll y)
{
return x / gcd(x,y) * y;
}
int main()
{
ios::sync_with_stdio(false);
cin>>n>>k;
for(ll i = 0; i < k; i++) cin>>a[i];
for(ll i = 1; i < (1 << k); i++)
{
ll res = 1, flag = 0;
for(ll j = 0; j < k; j++)
{
if(i & (1 << j))
{
res = lcm(res, a[j]);
flag++;
}
}
if(flag & 1) ans += (n/res);
else ans -= (n/res);
}
cout<<n-ans;
return 0;
}

最新文章

  1. SQL中的with as
  2. 刷连记录的迟到检测---Table表格增加一列值
  3. Python学习二---字符串
  4. freemarke之TemplateDirectiveModel详解
  5. 在外国网站上看到一个用artoolKit做的demo,学习了用gcd创建单列
  6. JS和H5做一个音乐播放器,附带源码
  7. Python学习笔记(Ⅰ)——Python程序结构与基础语法
  8. 2016310Exp5 MSF基础应用
  9. Java+opencv实现人脸检测
  10. C++中的STL中map用法详解
  11. ZOJ 1457 Prime Ring Problem(dfs+剪枝)
  12. Detecting Underlying Linux Distro
  13. mysql中&quot; &#39; &quot;和 &quot; ` &quot;的区别
  14. anycast简单总结
  15. form表单上传文件
  16. PS作业
  17. 2019.03.21 读书笔记 基元类型的Parse与TryParse 性能与建议
  18. hibernate课程 初探单表映射2-7 hbm配置文件常用设置
  19. PHP计算今天、昨天、本周、本月、上月开始时间和结束时间
  20. 干货:排名前16的Java工具类

热门文章

  1. document.getElementsByTagName
  2. MySQL prompt命令
  3. mysql启动服务出错--发生系统错误 1067。
  4. asp.net core 错误定位 &amp; vs2017 远程调试部署在centos上的asp.net core程序
  5. CSS属性: 阴影 轮廓 渐变
  6. Linux文件系统的实现 ZZ
  7. myEclipse mybatis自动生成工具xml配置
  8. eclipse tomcat jdk 版本引用
  9. linu常用命令链接
  10. Python学习---模版/包的概念