当前位置:网站首页>容斥原理 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);
}
原创不易
转载请标明出处
如果对你有所帮助 别忘啦点赞支持哈
边栏推荐
- Knapsack model acwing 1024. Packing problem
- 神经网络学习笔记
- Antd table+checkbox default value display
- 中国剩余定理 AcWing 204. 表达整数的奇怪方式
- C language 2: find the maximum value of three numbers, find the middle value of three numbers, and write program steps
- 洛谷 P3052 [USACO12MAR]Cows in a Skyscraper G
- 数字三角形模型 AcWing 1027. 方格取数
- KEPServer配置
- Thank you for your likes and attention
- Where is the big data open source project, one-stop fully automated full life cycle operation and maintenance steward Chengying (background)?
猜你喜欢

The longest ascending subsequence model acwing 1017. The glider wing of the strange thief Kidd

数字三角形模型 AcWing 1018. 最低通行费

Antd table+checkbox default value display

求组合数 AcWing 889. 满足条件的01序列

Sort th in antd table to prevent hovering color change +table hovering row color change +table header color change

How to build a real-time development platform to deeply release the value of enterprise real-time data?

Non progressive phenomena of entropy and morphology

Wechat push - template message parameter configuration

The influence of the number of non-zero values in the picture on Classification

The difference of iteration number and information entropy
随机推荐
Object array de duplication
高斯消元 AcWing 883. 高斯消元解线性方程组
4 search insertion location
How to assemble a registry
Miscellaneous records of Finance
IO stream_ Character stream, IO stream summary, IO stream case summary
发动机悬置系统冲击仿真-瞬时模态动态分析与响应谱分析
An article reveals the NFT strategy of traditional game manufacturers such as Ubisoft
349两个数组的交集和01两数之和
2022 Niuke multi school training (3) a-ancestor topic translation
What changes will metauniverse bring to the music industry in the trillion market?
博弈论 AcWing 893. 集合-Nim游戏
Yum source installation
背包问题 AcWing 9. 分组背包问题
涌现与形态的局部差异和整体差异
The article will not keep VIP charges all the time. It will be open for a period of time
Background color style modification on table hover in antd
A deep analysis of the soul of C language -- pointer
How to build a real-time development platform to deeply release the value of enterprise real-time data?
Real time development platform construction practice, in-depth release of real-time data value - 04 live broadcast review
