当前位置:网站首页>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 
边栏推荐
- Error ora-28547 or ora-03135 when Navicat connects to Oracle Database
- [rust notes] 15 string and text (Part 1)
- Daily question 1189 Maximum number of "balloons"
- Applicable to Net free barcode API [off] - free barcode API for NET [closed]
- MySQL advanced part 2: SQL optimization
- Leetcode-22: bracket generation
- MySQL advanced part 2: optimizing SQL steps
- 1.13 - RISC/CISC
- 5.Oracle-錶空間
- Bit of MySQL_ OR、BIT_ Count function
猜你喜欢
![[2021]GIRAFFE: Representing Scenes as Compositional Generative Neural Feature Fields](/img/65/7fa32cd0005ddaaebacd85c25e0c7e.jpg)
[2021]GIRAFFE: Representing Scenes as Compositional Generative Neural Feature Fields

Leetcode-6111: spiral matrix IV
![[wustctf2020] plain_ WP](/img/66/fdf7649359f36444703ff2279562e6.jpg)
[wustctf2020] plain_ WP

区间问题 AcWing 906. 区间分组

Matrixdb V4.5.0 was launched with a new mars2 storage engine!

Single chip computer engineering experience - layered idea

容斥原理 AcWing 890. 能被整除的数

4. Oracle redo log file management

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

SQL三种连接:内连接、外连接、交叉连接
随机推荐
4. 对象映射 - Mapping.Mapster
[BMZCTF-pwn] ectf-2014 seddit
Groupbykey() and reducebykey() and combinebykey() in spark
[2021]IBRNet: Learning Multi-View Image-Based Rendering Qianqian
求组合数 AcWing 887. 求组合数 III
Open source storage is so popular, why do we insist on self-development?
Alibaba established the enterprise digital intelligence service company "Lingyang" to focus on enterprise digital growth
栈 AcWing 3302. 表达式求值
SQL三种连接:内连接、外连接、交叉连接
Error ora-28547 or ora-03135 when Navicat connects to Oracle Database
2022-5-第四周日报
20220213-CTF MISC-a_ good_ Idea (use of stegsolve tool) -2017_ Dating_ in_ Singapore
[2020]GRAF: Generative Radiance Fields for 3D-Aware Image Synthesis
Liunx starts redis
Leetcode-6110: number of incremental paths in the grid graph
What is socket? Basic introduction to socket
C job interview - casting and comparing - C job interview - casting and comparing
Sum of three terms (construction)
[leetcode] day94 reshape matrix
RecyclerView的应用
