当前位置:网站首页>容斥原理(能被整除的数)
容斥原理(能被整除的数)
2022-06-13 10:57:00 【重生之我会拧瓶盖】
能被整除的数
给定一个整数 n 和 m 个不同的质数 p1,p2,…,pm。
请你求出 1∼n 中能被 p1,p2,…,pm 中的至少一个数整除的整数有多少个。
输入格式
第一行包含整数 n 和 m。
第二行包含 m 个质数。
输出格式
输出一个整数,表示满足条件的整数的个数。
数据范围
1≤m≤16,
1≤n,pi≤109
输入样例:
10 2
2 3
输出样例:
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;
}
边栏推荐
- Environ. Sci. Technol. (if=9.028) | impact of urban greening on atmospheric environment
- Vivo large scale kubernetes cluster automation operation and maintenance practice
- Similarities and differences between decoration mode and agency mode
- Folder data synchronization tool sync folders Pro
- [cloud enjoying freshness] community weekly · vol.66- Huawei partners and Developers Conference 2022 wonderful agenda announcement
- 【20220526】UE5.0.2 release d11782b
- Web 3.0?高成本版的P2P而已
- About instruction set bits and instruction architecture bits
- 宝塔中navicat连接mysql
- 《气候韧性和可持续性》| 新研究表明超级飓风未来几年会对南亚产生更大破坏
猜你喜欢
宝塔访问从IP改为域名
文件夹数据同步工具Sync Folders Pro
等个有“源”人|OpenHarmony 成长计划学生挑战赛报名启动
实战模拟│企业微信机器人实时报错预警
vivo大规模 Kubernetes 集群自动化运维实践
Introduction to binary tree
Record several interesting XSS vulnerability discoveries
Actual combat simulation │ real time error alarm of enterprise wechat robot
go-zero微服务实战系列(三、API定义和表结构设计)
Mysql database conceptual design using E-R model
随机推荐
Pytorch basis (II) -- tensor and gradient
D evaluate twice map
[elm classification] data classification based on particle swarm optimization convolution neural network CNN combined with limit learning machine elm with matlab code
Electrolytic capacitor, tantalum capacitor, ordinary capacitor
Vivo large scale kubernetes cluster automation operation and maintenance practice
2022年劳务员-通用基础(劳务员)上岗证题目及答案
《气候韧性和可持续性》| 新研究表明超级飓风未来几年会对南亚产生更大破坏
什么是400G以太网?
Full stack development practice | integrated development of SSM framework
Actual combat simulation │ real time error alarm of enterprise wechat robot
【20220526】UE5.0.2 release d11782b
Pagoda access changed from IP to domain name
ADG备库MRP0状态WAIT_FOR_GAP
Wait for someone with "source" | openharmony growth plan student challenge registration to start
首个Laravel工作流引擎发布 V1.0正式版
Navicat connection MySQL in Pagoda
Codeforces Round #798 (Div. 2)ABCD
Initial installation and use of redis [play with Huawei cloud]
Nature communications - modeling armed conflict risk under climate change using machine learning and time series data
Environ. Sci. Technol.(IF=9.028) | 城市绿化对大气环境的影响