当前位置:网站首页>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
边栏推荐
- Leetcode-31: next spread
- 博弈论 AcWing 893. 集合-Nim游戏
- MySQL advanced part 1: triggers
- Leetcode array operation
- 20220213-CTF MISC-a_ good_ Idea (use of stegsolve tool) -2017_ Dating_ in_ Singapore
- Leetcode divide and conquer / dichotomy
- [leetcode] day95 effective Sudoku & matrix zeroing
- 背包问题 AcWing 9. 分组背包问题
- Alibaba established the enterprise digital intelligence service company "Lingyang" to focus on enterprise digital growth
- WordPress switches the page, and the domain name changes back to the IP address
猜你喜欢
随机推荐
[rust notes] 14 set (Part 1)
11-gorm-v2-02-create data
论文阅读报告
Liunx starts redis
5.Oracle-表空间
MySQL advanced part 2: storage engine
Leetcode-6110: number of incremental paths in the grid graph
Alibaba established the enterprise digital intelligence service company "Lingyang" to focus on enterprise digital growth
博弈论 AcWing 891. Nim游戏
快速使用Amazon MemoryDB并构建你专属的Redis内存数据库
International Open Source firmware Foundation (osff) organization
How to understand the definition of sequence limit?
[moviepy] unable to find a solution for exe
Single chip computer engineering experience - layered idea
[rust notes] 16 input and output (Part 1)
Ffmpeg build download (including old version)
Day 2 document
Leetcode-22: bracket generation
Leetcode-3: Longest substring without repeated characters
MySQL advanced part 1: View