当前位置:网站首页>容斥原理 AcWing 890. 能被整除的数
容斥原理 AcWing 890. 能被整除的数
2022-07-27 10:35: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);
}
原创不易
转载请标明出处
如果对你有所帮助 别忘啦点赞支持哈
边栏推荐
- What is the issuing price of NFT (Interpretation of NFT and establishment of NFT world outlook)
- 数字三角形模型 AcWing 1015. 摘花生
- SQL Server2000 database error
- 泰山OFFICE技术讲座:缩放比例与打开文件
- A deep analysis of the soul of C language -- pointer
- tensorflow运行报错解决方法
- Neural network learning notes
- 迭代次数和熵之间关系的一个验证试验
- 最长上升子序列模型 AcWing 272. 最长公共上升子序列
- Kangaroo cloud stack based on CBO in spark SQL optimization
猜你喜欢

Backpack model acwing 1022. Collection of pet elves

Kangaroo cloud stack based on CBO in spark SQL optimization

区间问题 AcWing 906. 区间分组

JVM judges that the object is dead, and practices verify GC recycling

Digital triangle model acwing 275. pass note
![Take you hand-in-hand to develop a complete classic game [Tetris] from scratch, with less than 200 lines of logic.](/img/7f/f42f9267cdff35522c260ef073bab9.png)
Take you hand-in-hand to develop a complete classic game [Tetris] from scratch, with less than 200 lines of logic.

发动机悬置系统冲击仿真-瞬时模态动态分析与响应谱分析

博弈论 AcWing 891. Nim游戏

IMG SRC is empty or SRC does not exist, and the picture has a white border

推导STO双中心动能积分的详细展开式
随机推荐
Local and overall differences between emergence and morphology
Non progressive phenomena of entropy and morphology
Maximized array sum after 13 K negations
properties文件
How to build a real-time development platform to deeply release the value of enterprise real-time data?
10 complete half of the questions
Play with the cluster configuration center and learn about the Taier console
Students, don't copy all my code, remember to change it, or we both want G
学习笔记-uni-app
解决 ImportError: cannot import name 'abs' 导入tensorflow报错
Background color style modification on table hover in antd
十年架构五年生活-07 年轻气盛的蜕变
NFT leaderboard -nft real offer latest address: NFT leaderboard.com
Why is the data service API the standard configuration of the data midrange when we take the last mile of the data midrange?
What is the mystery of the gate of the meta universe?
Longest ascending subsequence model acwing 1010. Interceptor missile
涌现与形态的局部差异和整体差异
SQL Server2000数据库错误
最长上升子序列模型 AcWing 1016. 最大上升子序列和
Wenzhou University X kangaroo cloud: how to "know well" in the construction of higher talent education
