当前位置:网站首页>Inclusion exclusion principle (number divisible)
Inclusion exclusion principle (number divisible)
2022-06-13 11:02:00 【I can screw the bottle cap when I am born again】
The number divisible
Given an integer n and m A different prime number p1,p2,…,pm.
Please find out 1∼n Middle energy quilt p1,p2,…,pm How many integers are divided by at least one number in .
Input format
The first line contains integers n and m.
The second line contains m A prime number .
Output format
Output an integer , Represents the number of integers that satisfy the condition .
Data range
1≤m≤16,
1≤n,pi≤109
sample input :
10 2
2 3
sample output :
7
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
int n,m;
int a[20];
int main()
{
ios::sync_with_stdio(false);
cin>>n>>m;
for (int i=0;i<m;i++) cin>>a[i];
int res = 0;
for (int i=1;i<1<<m;i++)
{
int t=1,s=0;
for (int j=0;j<m;j++)
{
if (i>>j&1) {
if ((LL)t*a[j]>n)
{
t = -1;
break;
}
t*=a[j];
s++;
}
}
if (t!=-1)
{
if (s%2) res+=n/t;
else
res-=n/t;
}
}
printf("%d",res);
return 0;
}
边栏推荐
- Nature communications - modeling armed conflict risk under climate change using machine learning and time series data
- d编译时生成唯一标识
- [cloud enjoying freshness] community weekly · vol.66- Huawei partners and Developers Conference 2022 wonderful agenda announcement
- Necessary for Architects: system capacity status checklist
- Advanced technology management - what management tools can managers use
- We spent a weekend migrating 3.7 million lines of code to typescript
- ue5 小知识点 random point in Bounding Boxf From Stream
- About instruction set bits and instruction architecture bits
- Do you agree that the salary of hardware engineers is falsely high?
- 恶意代码实战分析Lab05-01
猜你喜欢
终于,月入 20000 !!
Develop a basic module with low code
Go 要加个箭头语法,这下更像 PHP 了!
Electrolytic capacitor, tantalum capacitor, ordinary capacitor
Use of servers
View the default MySQL password in the pagoda
恶意代码实战分析Lab05-01
Vivo large scale kubernetes cluster automation operation and maintenance practice
第七章 文件管理作业
硬件工程师薪资虚高,你认可吗?
随机推荐
Read pgstat [this time Gauss is not a mathematician]
Vivo large scale kubernetes cluster automation operation and maintenance practice
Codeforces Round #798 (Div. 2)ABCD
Flutter simple and excellent open source dialog uses free_ dialog
Brief introduction of class file structure and class loading process execution engine
Acwing game 55
Deploy vscode on kubernetes cluster
Environ. Sci. Technol. (if=9.028) | impact of urban greening on atmospheric environment
d编译时生成唯一标识
ue5 小知识点 random point in Bounding Boxf From Stream
[cloud enjoying freshness] community weekly · vol.66- Huawei partners and Developers Conference 2022 wonderful agenda announcement
Questions and answers of the labor worker general basic (labor worker) work license in 2022
Database learning notes (Chapter 16)
AcWing第 55 场周赛
Multithreading starts from the lockless queue of UE4 (thread safe)
Some experience in database table structure design
Alibaba's employees decreased by 4000 in the first quarter; Programmers wrote scripts to hang up vaccine numbers and were arrested for making a profit of 400000 yuan; Sohu encounters epic email fraud,
Develop a basic module with low code
Vivo large scale kubernetes cluster automation operation and maintenance practice
spark源码(一)spark-submit如何将jar以及配置参数提交给spark服务器