当前位置:网站首页>Inclusion exclusion principle acwing 890 Divisible number
Inclusion exclusion principle acwing 890 Divisible number
2022-07-05 06:24:00 【T_ Y_ F666】
Principle of tolerance and exclusion AcWing 890. The number divisible
Original link
AcWing 890. The number divisible
Algorithm tags
Principle of tolerance and exclusion
Ideas
Code
#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;
// Enumerate from 1 To 1111...(m individual 1) Every set state of , ( Select at least one set )
rep(i, 1, 1<<m){
// t Represents the product of prime numbers cnt Indicates the number of current selection sets
int t=1, cnt=0;
rep(j, 0, m){
if(i>>j&1){
// The product is greater than n, be n/t = 0, Jump out of this cycle
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);
}
Originality is not easy.
Reprint please indicate the source
If it helps you Don't forget to praise and support
边栏推荐
- Record the process of configuring nccl and horovod in these two days (original)
- Doing SQL performance optimization is really eye-catching
- Network security skills competition in Secondary Vocational Schools -- a tutorial article on middleware penetration testing in Guangxi regional competition
- Leetcode-6111: spiral matrix IV
- TCP's understanding of three handshakes and four waves
- 中国剩余定理 AcWing 204. 表达整数的奇怪方式
- International Open Source firmware Foundation (osff) organization
- One question per day 1020 Number of enclaves
- MySQL advanced part 1: index
- MPLS experiment
猜你喜欢
MySQL advanced part 1: View
There are three kinds of SQL connections: internal connection, external connection and cross connection
传统数据库逐渐“难适应”,云原生数据库脱颖而出
求组合数 AcWing 889. 满足条件的01序列
MatrixDB v4.5.0 重磅发布,全新推出 MARS2 存储引擎!
Operator priority, one catch, no doubt
高斯消元 AcWing 884. 高斯消元解异或線性方程組
背包问题 AcWing 9. 分组背包问题
4. 对象映射 - Mapping.Mapster
Redis-01.初识Redis
随机推荐
Leetcode-6111: spiral matrix IV
MySQL advanced part 1: stored procedures and functions
11-gorm-v2-03-basic query
3. Oracle control file management
MPLS experiment
5.Oracle-錶空間
Ffmpeg build download (including old version)
Redis-01.初识Redis
Matrixdb V4.5.0 was launched with a new mars2 storage engine!
2048项目实现
MySQL advanced part 2: MySQL architecture
SPI details
【LeetCode】Day94-重塑矩阵
C Primer Plus Chapter 15 (bit operation)
Dataframe (1): introduction and creation of dataframe
【LeetCode】Easy | 20. Valid parentheses
In depth analysis of for (VaR I = 0; I < 5; i++) {settimeout (() => console.log (I), 1000)}
7.Oracle-表结构
Leetcode recursion
[leetcode] day94 reshape matrix