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