当前位置:网站首页>容斥原理 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);
}
原创不易
转载请标明出处
如果对你有所帮助 别忘啦点赞支持哈
边栏推荐
- 可变电阻器概述——结构、工作和不同应用
- SQL三种连接:内连接、外连接、交叉连接
- Leetcode-6111: spiral matrix IV
- Network security skills competition in Secondary Vocational Schools -- a tutorial article on middleware penetration testing in Guangxi regional competition
- Data visualization chart summary (I)
- 传统数据库逐渐“难适应”,云原生数据库脱颖而出
- MIT-6874-Deep Learning in the Life Sciences Week 7
- Leetcode recursion
- 927. 三等分 模拟
- One question per day 1020 Number of enclaves
猜你喜欢
Appium automation test foundation - Summary of appium test environment construction
LeetCode 0108. Convert an ordered array into a binary search tree - the median of the array is the root, and the left and right of the median are the left and right subtrees respectively
leetcode-6110:网格图中递增路径的数目
1.14 - 流水线
SPI details
1.14 - assembly line
redis发布订阅命令行实现
Sqlmap tutorial (II) practical skills I
什么是套接字?Socket基本介绍
Open source storage is so popular, why do we insist on self-development?
随机推荐
Leetcode-6108: decrypt messages
927. 三等分 模拟
WordPress switches the page, and the domain name changes back to the IP address
liunx启动redis
数据可视化图表总结(一)
Flutter Web 硬件键盘监听
Niu Mei's math problems
实时时钟 (RTC)
Collection: programming related websites and books
[rust notes] 15 string and text (Part 1)
One question per day 1020 Number of enclaves
leetcode-1200:最小绝对差
11-gorm-v2-03-basic query
【Rust 笔记】16-输入与输出(上)
Leetcode-6109: number of people who know secrets
高斯消元 AcWing 884. 高斯消元解异或线性方程组
做 SQL 性能优化真是让人干瞪眼
__ builtin_ Popcount() counts the number of 1s, which are commonly used in bit operations
New title of module a of "PanYun Cup" secondary vocational network security skills competition
【Rust 笔记】16-输入与输出(下)