当前位置:网站首页>容斥原理 AcWing 890. 能被整除的数
容斥原理 AcWing 890. 能被整除的数
2022-07-05 06:16:00 【T_Y_F666】
容斥原理 AcWing 890. 能被整除的数
原题链接
算法标签
容斥原理
思路
代码
#include<bits/stdc++.h>
#define int long long
#define abs fabs
#define rep(i, a, b) for(int i=a;i<b;++i)
#define Rep(i, a, b) for(int i=a;i>=b;--i)
using namespace std;
const int N = 20;
int a[N];
inline int read(){
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return s*w;
}
void put(int x) {
if(x<0) putchar('-'),x=-x;
if(x>=10) put(x/10);
putchar(x%10^48);
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n=read(), m=read();
rep(i, 0, m){
a[i]=read();
}
int res=0;
// 枚举从1 到 1111...(m个1)的每一个集合状态, (至少选中一个集合)
rep(i, 1, 1<<m){
// t表示质数乘积 cnt表示当前选法集合数量
int t=1, cnt=0;
rep(j, 0, m){
if(i>>j&1){
// 乘积大于n, 则n/t = 0, 跳出这轮循环
if(t*a[j]>n){
t=-1;
break;
}
cnt++;
t*=a[j];
}
}
if(t!=-1){
if(cnt%2){
res+=n/t;
}else{
res-=n/t;
}
}
}
printf("%lld", res);
}
原创不易
转载请标明出处
如果对你有所帮助 别忘啦点赞支持哈
边栏推荐
- [rust notes] 17 concurrent (Part 1)
- Real time clock (RTC)
- NotImplementedError: Cannot convert a symbolic Tensor (yolo_boxes_0/meshgrid/Size_1:0) to a numpy ar
- TypeScript 基础讲解
- Leetcode-6109: number of people who know secrets
- Usage scenarios of golang context
- Leetcode-31: next spread
- Records of some tools 2022
- 4. 对象映射 - Mapping.Mapster
- LeetCode-54
猜你喜欢

【LeetCode】Easy | 20. Valid parentheses

MySQL怎么运行的系列(八)14张图说明白MySQL事务原子性和undo日志原理

可变电阻器概述——结构、工作和不同应用

Appium foundation - use the first demo of appium

数据可视化图表总结(二)

Spark中groupByKey() 和 reduceByKey() 和combineByKey()

MIT-6874-Deep Learning in the Life Sciences Week 7

wordpress切换页面,域名变回了IP地址

MySQL advanced part 2: storage engine

1.14 - 流水线
随机推荐
Arduino 控制的 RGB LED 无限镜
Data visualization chart summary (I)
【Rust 笔记】16-输入与输出(下)
A reason that is easy to be ignored when the printer is offline
Leetcode-6108: decrypt messages
阿里新成员「瓴羊」正式亮相,由阿里副总裁朋新宇带队,集结多个核心部门技术团队
【LeetCode】Day94-重塑矩阵
Niu Mei's math problems
数据可视化图表总结(一)
Leetcode dynamic programming
Liunx starts redis
Simple selection sort of selection sort
Leetcode-31: next spread
leetcode-6111:螺旋矩阵 IV
打印机脱机时一种容易被忽略的原因
[rust notes] 13 iterator (Part 2)
高斯消元 AcWing 884. 高斯消元解异或线性方程组
1.15 - input and output system
11-gorm-v2-02-create data
SPI 详解
