当前位置:网站首页>Inclusion exclusion principle acwing 890. divisible numbers
Inclusion exclusion principle acwing 890. divisible numbers
2022-07-27 11:18: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 
边栏推荐
- 4 search insertion location
- Luogu p1896 non aggression
- 最长上升子序列模型 AcWing 1016. 最大上升子序列和
- 2022 Niuke multi school training (3) a-ancestor topic translation
- 求组合数 AcWing 886. 求组合数 II
- TensorFlow张量运算函数集
- Yiwen counts NFT projects valued at more than US $100million
- 2022牛客多校训练(3)A-Ancestor 题目翻译
- 2022牛客多校 (3)J.Journey
- 解决 ImportError: cannot import name 'abs' 导入tensorflow报错
猜你喜欢

How to assemble a registry

15 design movie rental system

树形DP AcWing 285. 没有上司的舞会

博弈论 AcWing 892. 台阶-Nim游戏

博弈论 AcWing 891. Nim游戏

如何组装一个注册中心

求组合数 AcWing 887. 求组合数 III

Based on the open source stream batch integrated data synchronization engine Chunjun data restore DDL parsing module actual combat sharing

最长上升子序列模型 AcWing 1012. 友好城市

Yiwen counts NFT projects valued at more than US $100million
随机推荐
pyquery 的使用
Non progressive phenomena of entropy and morphology
Knapsack model acwing 423. Picking herbs
JVM judges that the object is dead, and practices verify GC recycling
博弈论 AcWing 894. 拆分-Nim游戏
Regular form form judgment
Solutions to errors in tensorflow operation
Yiwen counts NFT projects valued at more than US $100million
Antd table+checkbox default value display
Use of beautifulsoup
求组合数 AcWing 887. 求组合数 III
求组合数 AcWing 886. 求组合数 II
解决 ImportError: cannot import name 'abs' 导入tensorflow报错
12 is at least twice the maximum number of other numbers
数字三角形模型 AcWing 275. 传纸条
The longest ascending subsequence model acwing 1016. The sum of the largest ascending subsequence
求组合数 AcWing 888. 求组合数 IV
What is the mystery of the gate of the meta universe?
Sort th in antd table to prevent hovering color change +table hovering row color change +table header color change
Luogu p1896 non aggression
