容斥原理
#include <iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#define LL long long
using namespace std;
int t,n,m;
LL ans,num[25];
int gcd(LL x,LL y)
{
LL t;
if(x>y)
{
t=x;
x=y;
y=t;
}
while(x)
{
t=x;
x=y%x;
y=t;
}
return y;
}
void dfs(int x,int k,LL j)
{
if(k==t)
{
if(j==0) //如果不加这句就会出现RE,我也不知道为什么
return ;
if(t&1)
ans+=n/j;
else
ans-=n/j;
// cout<<ans<<endl;
return;
}
for(int i=x+1;i<m;i++)
{
dfs(i,k+1,j*num[i]/(gcd(j,num[i])));
}
return ;
}
int main()
{
int i;
while(scanf("%d%d",&n,&m)!=EOF)
{
memset(num,0,sizeof(num));
for(i=0;i<m;i++)
scanf("%I64d",&num[i]);
n--;
ans=0;
for(t=1;t<=m;t++)
{
dfs(-1,0,1);
}
printf("%I64d\n",ans);
}
return 0;
}