AcWing 890. 能被整除的数
原题链接
简单
作者:
Drifter
,
2021-01-20 00:18:18
,
所有人可见
,
阅读 292
进阶 Day 4
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 20;
typedef long long LL;
int n, m;
int p[N];
int main(void)
{
scanf("%d%d", &n, &m);
for (int i = 0; i < m; i++) scanf("%d", &p[i]);
int res = 0;
for (int i = 1; i < 1 << m; i++)
{
int t = 1, cnt = 0;
for (int j = 0; j < m; j++)
{
if (i >> j & 1)
{
if ((LL)t * p[j] > n)
{
t = -1;
break;
}
cnt++;
t = (LL)t * p[j];
}
}
if (t != -1)
{
if (cnt % 2) res += n / t;
else res -= n / t;
}
}
printf("%d\n", res);
return 0;
}