当前位置:网站首页>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 
边栏推荐
- What is socket? Basic introduction to socket
- Sword finger offer II 058: schedule
- Suppose a bank's ATM machine, which allows users to deposit and withdraw money. Now there is 200 yuan in an account, and both user a and user B have the right to deposit and withdraw money from this a
- MatrixDB v4.5.0 重磅发布,全新推出 MARS2 存储引擎!
- 博弈论 AcWing 893. 集合-Nim游戏
- 4.Oracle-重做日志文件管理
- Network security skills competition in Secondary Vocational Schools -- a tutorial article on middleware penetration testing in Guangxi regional competition
- MySQL advanced part 2: the use of indexes
- C Primer Plus Chapter 15 (bit operation)
- 4. Object mapping Mapster
猜你喜欢

SPI details

【LeetCode】Easy | 20. Valid parentheses

ollvm编译出现的问题纪录

P2575 master fight

There are three kinds of SQL connections: internal connection, external connection and cross connection

4.Oracle-重做日志文件管理

Install opencv -- CONDA to establish a virtual environment and add the kernel of this environment in jupyter

Bit of MySQL_ OR、BIT_ Count function

LeetCode-54

2021apmcm post game Summary - edge detection
随机推荐
TCP's understanding of three handshakes and four waves
MySQL怎么运行的系列(八)14张图说明白MySQL事务原子性和undo日志原理
Liunx starts redis
Erreur de connexion Navicat à la base de données Oracle Ora - 28547 ou Ora - 03135
Single chip computer engineering experience - layered idea
[rust notes] 17 concurrent (Part 1)
快速使用Amazon MemoryDB并构建你专属的Redis内存数据库
5. Oracle TABLESPACE
20220213-CTF MISC-a_ good_ Idea (use of stegsolve tool) -2017_ Dating_ in_ Singapore
2048 project realization
2022/6/29-日报
11-gorm-v2-02-create data
[rust notes] 15 string and text (Part 1)
Leetcode heap correlation
How to generate an image from text on fly at runtime
Records of some tools 2022
Usage scenarios of golang context
Alibaba established the enterprise digital intelligence service company "Lingyang" to focus on enterprise digital growth
MySQL advanced part 2: the use of indexes
Regulations for network security events of vocational group in 2022 Guizhou Vocational College skill competition
