当前位置:网站首页>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 
边栏推荐
- Shock simulation of engine mounting system transient modal dynamic analysis and response spectrum analysis
- Longest ascending subsequence model acwing 1010. Interceptor missile
- Use of parsel
- An article reveals the NFT strategy of traditional game manufacturers such as Ubisoft
- 求组合数 AcWing 887. 求组合数 III
- Solutions to errors in tensorflow operation
- Learning notes uni app
- Learning notes - wechat payment
- Tree data conversion
- 2022牛客多校训练(3)A-Ancestor 题目翻译
猜你喜欢

Use of parsel

How to build a real-time development platform to deeply release the value of enterprise real-time data?

2022 Niuke multi school (3) j.journey

Caused by:org.gradle.api.internal.plugins . PluginApplicationException: Failed to apply plugin

properties文件

The difference of iteration number and information entropy

Digital triangle model acwing 275. pass note

Shortest moving distance and entropy of morphological complex

博弈论 AcWing 891. Nim游戏

中国剩余定理 AcWing 204. 表达整数的奇怪方式
随机推荐
Non progressive phenomena of entropy and morphology
6 find the smallest letter larger than the target letter
Internal and external troubles of digital collection NFT "boring ape" bayc
求组合数 AcWing 885. 求组合数 I
Use of beautifulsoup
记忆化搜索 AcWing 901. 滑雪
Longest ascending subsequence model acwing 272. longest common ascending subsequence
高斯消元 AcWing 884. 高斯消元解异或线性方程组
XXX packages are looking for funding run 'NPM fund' for details solutions
Based on the open source stream batch integrated data synchronization engine Chunjun data restore DDL parsing module actual combat sharing
Kangaroo cloud stack based on CBO in spark SQL optimization
JVM judges that the object is dead, and practices verify GC recycling
10 complete half of the questions
Ansible
洛谷P1441 砝码称重
An article reveals the NFT strategy of traditional game manufacturers such as Ubisoft
Caused by:org.gradle.api.internal.plugins . PluginApplicationException: Failed to apply plugin
SQL Server2000数据库错误
BeautifulSoup的使用
2022 Niuke multi school (3) j.journey
