当前位置:网站首页>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
边栏推荐
猜你喜欢
博弈论 AcWing 894. 拆分-Nim游戏
Matrixdb V4.5.0 was launched with a new mars2 storage engine!
Operator priority, one catch, no doubt
MySQL advanced part 1: View
中国剩余定理 AcWing 204. 表达整数的奇怪方式
[2021]IBRNet: Learning Multi-View Image-Based Rendering Qianqian
Error ora-28547 or ora-03135 when Navicat connects to Oracle Database
Is it impossible for lamda to wake up?
MySQL advanced part 2: optimizing SQL steps
5. Oracle tablespace
随机推荐
[rust notes] 17 concurrent (Part 2)
LeetCode-54
1.13 - RISC/CISC
How to set the drop-down arrow in the spinner- How to set dropdown arrow in spinner?
Leetcode-6108: decrypt messages
Dataframe (1): introduction and creation of dataframe
阿里新成员「瓴羊」正式亮相,由阿里副总裁朋新宇带队,集结多个核心部门技术团队
Sqlmap tutorial (1)
Leetcode array operation
Leetcode backtracking method
Open source storage is so popular, why do we insist on self-development?
Sqlmap tutorial (II) practical skills I
[rust notes] 16 input and output (Part 1)
Leetcode recursion
C - XOR to all (binary topic)
MySQL advanced part 1: index
Niu Mei's math problems
Traditional databases are gradually "difficult to adapt", and cloud native databases stand out
Sorting out the latest Android interview points in 2022 to help you easily win the offer - attached is the summary of Android intermediate and advanced interview questions in 2022
Records of some tools 2022