当前位置:网站首页>容斥原理 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);
}
原创不易
转载请标明出处
如果对你有所帮助 别忘啦点赞支持哈
边栏推荐
- Today's code farmer girl learned notes about event operation and ref attribute, and did the practice of form two-way binding
- Use of pyquery
- Sorry, you guys have something to deal with in the bank recently, which has been delayed
- Longest ascending subsequence model acwing 1010. Interceptor missile
- Digital triangle model acwing 275. pass note
- 洛谷P1896 互不侵犯
- 2022牛客多校 (3)J.Journey
- Derive the detailed expansion of STO double center kinetic energy integral
- Where is the big data open source project, one-stop fully automated full life cycle operation and maintenance steward Chengying (background)?
- 【FPGA教程案例40】通信案例10——基于FPGA的简易OFDM系统verilog实现
猜你喜欢

区间问题 AcWing 906. 区间分组

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

c语言指针函数和函数指针的辨析

Asustek unparalleled, this may be the best affordable high brush thin notebook on the screen

最长上升子序列模型 AcWing 272. 最长公共上升子序列

Shock simulation of engine mounting system transient modal dynamic analysis and response spectrum analysis

pyquery 的使用

properties文件

Knapsack model acwing 423. Picking herbs

A verification test of the relationship between iteration number and entropy
随机推荐
学习笔记-简易服务器实现
An article reveals the NFT strategy of traditional game manufacturers such as Ubisoft
背包模型 AcWing 423. 采药
NFT leaderboard -nft real offer latest address: NFT leaderboard.com
Analysis of C language pointer function and function pointer
Why is the data service API the standard configuration of the data midrange when we take the last mile of the data midrange?
tensorflow运行报错解决方法
区间问题 AcWing 906. 区间分组
荒野觅踪---寻找迭代次数
最长上升子序列模型 AcWing 1016. 最大上升子序列和
Use of beautifulsoup
数字三角形模型 AcWing 1018. 最低通行费
The influence of the number of non-zero values in the picture on Classification
Antd table+checkbox default value display
学习笔记-uni-app
背包模型 AcWing 1024. 装箱问题
11 wrong set
Real time development platform construction practice, in-depth release of real-time data value - 04 live broadcast review
2022牛客多校 (3)J.Journey
Longest ascending subsequence model acwing 1012. Sister Cities
