当前位置:网站首页>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 
边栏推荐
- [rust notes] 14 set (Part 1)
- [rust notes] 15 string and text (Part 1)
- Sword finger offer II 058: schedule
- 背包问题 AcWing 9. 分组背包问题
- 4.Oracle-重做日志文件管理
- How to understand the definition of sequence limit?
- 2021apmcm post game Summary - edge detection
- [learning] database: several cases of index failure
- Erreur de connexion Navicat à la base de données Oracle Ora - 28547 ou Ora - 03135
- Leetcode stack related
猜你喜欢

博弈论 AcWing 894. 拆分-Nim游戏

Open source storage is so popular, why do we insist on self-development?

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

Leetcode array operation

International Open Source firmware Foundation (osff) organization

SPI details

阿里巴巴成立企业数智服务公司“瓴羊”,聚焦企业数字化增长

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

NotImplementedError: Cannot convert a symbolic Tensor (yolo_boxes_0/meshgrid/Size_1:0) to a numpy ar

区间问题 AcWing 906. 区间分组
随机推荐
Liunx starts redis
求组合数 AcWing 887. 求组合数 III
2022/6/29-日报
Presentation of attribute value of an item
1.15 - input and output system
P2575 master fight
MySQL advanced part 2: storage engine
Gauss Cancellation acwing 884. Solution d'un système d'équations Xor linéaires par élimination gaussienne
How to understand the definition of sequence limit?
LeetCode 0107. Sequence traversal of binary tree II - another method
Leetcode-6111: spiral matrix IV
Currently clicked button and current mouse coordinates in QT judgment interface
Navicat連接Oracle數據庫報錯ORA-28547或ORA-03135
[2020]GRAF: Generative Radiance Fields for 3D-Aware Image Synthesis
MPLS experiment
Sorting out the latest Android interview points in 2022 to help you easily win the offer - attached is the summary of Android intermediate and advanced interview questions in 2022
Applicable to Net free barcode API [off] - free barcode API for NET [closed]
Bit of MySQL_ OR、BIT_ Count function
[wustctf2020] plain_ WP
中国剩余定理 AcWing 204. 表达整数的奇怪方式
