当前位置:网站首页>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 
边栏推荐
- Neural network learning notes
- Kangaroo cloud stack based on CBO in spark SQL optimization
- Non progressive phenomena of entropy and morphology
- Caused by:org.gradle.api.internal.plugins . PluginApplicationException: Failed to apply plugin
- 最长上升子序列模型 AcWing 482. 合唱队形
- Play with the cluster configuration center and learn about the Taier console
- 2022 Niuke multi school (3) j.journey
- 树形DP AcWing 285. 没有上司的舞会
- 数字三角形模型 AcWing 275. 传纸条
- The article will not keep VIP charges all the time. It will be open for a period of time
猜你喜欢

Use of beautifulsoup

Longest ascending subsequence model acwing 272. longest common ascending subsequence

Longest ascending subsequence model acwing 1014. mountaineering

A verification test of the relationship between iteration number and entropy

数字三角形模型 AcWing 1027. 方格取数

最长上升子序列模型 AcWing 1010. 拦截导弹

栈 AcWing 3302. 表达式求值

最长上升子序列模型 AcWing 1016. 最大上升子序列和

Use of parsel

Wenzhou University X kangaroo cloud: how to "know well" in the construction of higher talent education
随机推荐
Luogu p1896 non aggression
力扣——10. 正则表达式匹配
如何组装一个注册中心
15th largest value of data flow
数字三角形模型 AcWing 1018. 最低通行费
Learning notes uni app
IO stream_ Overview and explanation of data input and output flow
A deep analysis of the soul of C language -- pointer
Today's code farmer girl summarized her notes about NPM package management and URL module
Background color style modification on table hover in antd
Learning notes - simple server implementation
A verification test of the relationship between iteration number and entropy
IO stream_ Character stream, IO stream summary, IO stream case summary
IMG SRC is empty or SRC does not exist, and the picture has a white border
Use of beautifulsoup
最长上升子序列模型 AcWing 1017. 怪盗基德的滑翔翼
How to create a.Net image with diagnostic tools
10 complete half of the questions
Cancer DDD
Instructions for mock platform
