当前位置:网站首页>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 
边栏推荐
- How to generate an image from text on fly at runtime
- Dataframe (1): introduction and creation of dataframe
- Series of how MySQL works (VIII) 14 figures explain the atomicity of MySQL transactions and the principle of undo logging
- 4. Object mapping Mapster
- Regulations for network security events of vocational group in 2022 Guizhou Vocational College skill competition
- Gauss Cancellation acwing 884. Solution d'un système d'équations Xor linéaires par élimination gaussienne
- How to set the drop-down arrow in the spinner- How to set dropdown arrow in spinner?
- [rust notes] 17 concurrent (Part 1)
- 传统数据库逐渐“难适应”,云原生数据库脱颖而出
- Simple selection sort of selection sort
猜你喜欢

1.13 - RISC/CISC

MySQL advanced part 2: MySQL architecture

背包问题 AcWing 9. 分组背包问题

LeetCode 0107. Sequence traversal of binary tree II - another method

Is it impossible for lamda to wake up?

高斯消元 AcWing 884. 高斯消元解异或线性方程组

WordPress switches the page, and the domain name changes back to the IP address

Open source storage is so popular, why do we insist on self-development?
![[moviepy] unable to find a solution for exe](/img/0a/4841f53cedc1333654b9443e406f4c.jpg)
[moviepy] unable to find a solution for exe

Leetcode stack related
随机推荐
区间问题 AcWing 906. 区间分组
背包问题 AcWing 9. 分组背包问题
WordPress switches the page, and the domain name changes back to the IP address
[rust notes] 14 set (Part 2)
Applicable to Net free barcode API [off] - free barcode API for NET [closed]
Chapter 6 relational database theory
论文阅读报告
2021apmcm post game Summary - edge detection
阿里新成员「瓴羊」正式亮相,由阿里副总裁朋新宇带队,集结多个核心部门技术团队
Single chip computer engineering experience - layered idea
MySQL advanced part 2: the use of indexes
TCP's understanding of three handshakes and four waves
NotImplementedError: Cannot convert a symbolic Tensor (yolo_boxes_0/meshgrid/Size_1:0) to a numpy ar
[leetcode] day95 effective Sudoku & matrix zeroing
Alibaba established the enterprise digital intelligence service company "Lingyang" to focus on enterprise digital growth
In depth analysis of for (VaR I = 0; I < 5; i++) {settimeout (() => console.log (I), 1000)}
Leetcode dynamic programming
SPI details
1.15 - input and output system
5.Oracle-錶空間
