当前位置:网站首页>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;
}
边栏推荐
- We spent a weekend migrating 3.7 million lines of code to typescript
- WinForm resolves frequent refresh of black screen
- Nim游戏阶梯 Nim游戏和SG函数应用(集合游戏)
- Environ. Sci. Technol. (if=9.028) | impact of urban greening on atmospheric environment
- Record several interesting XSS vulnerability discoveries
- The road of ospo construction of Weibo: how to promote enterprise open source through ospo construction?
- Necessary for Architects: system capacity status checklist
- Go 要加个箭头语法,这下更像 PHP 了!
- 2022 coal mine water exploration and drainage special operation certificate examination question bank simulated examination platform operation
- Go zero microservice Practice Series (III. API definition and table structure design)
猜你喜欢

ue5 小知识点 random point in Bounding Boxf From Stream

Do you agree that the salary of hardware engineers is falsely high?

数据库学习笔记(第十五章)

Use of servers

Actual combat simulation │ real time error alarm of enterprise wechat robot

Nim游戏阶梯 Nim游戏和SG函数应用(集合游戏)

How to optimize MySQL?

Finally, the monthly income is 20000!!

Talk about MySQL indexing mechanism

flutter简单优秀的开源dialog使用free_dialog
随机推荐
Go needs to add an arrow syntax, which is more like PHP!
Simple query cost estimation [Gauss is not a mathematician this time]
CommonAPI与AUTOSAR AP通讯管理的异同
判定二分图和二分图最大匹配
区间修改乘和加(理解懒标记的好例题)
Understanding RPC and rest
Advanced technology management - what management tools can managers use
WinForm resolves frequent refresh of black screen
元宇宙土地:是什么让数字房地产变得有价值
SSM integration preliminary details
On the exploitation of a horizontal ultra vires vulnerability
Private computing fat core concepts and stand-alone deployment
Actual combat simulation │ real time error alarm of enterprise wechat robot
Record several interesting XSS vulnerability discoveries
Go zero microservice Practice Series (III. API definition and table structure design)
[elm classification] data classification based on particle swarm optimization convolution neural network CNN combined with limit learning machine elm with matlab code
Web3 system construction: principles, models and methods of decentralization (Part I)
pyepics下载和安装
Codeforces Round #798 (Div. 2)ABCD
Ubuntu installs MySQL compressed package for future reference