Pagini recente » Cod sursa (job #369043) | Cod sursa (job #249337) | Cod sursa (job #253326) | Cod sursa (job #2740611) | Cod sursa (job #549755)
Cod sursa(job #549755)
#include <cstdio>
FILE *in,*out;
int d[30],k;
long long rez,n;
long long cmmdc(long long x,long long y)
{
long long aux;
while (y)
{
aux=x;
x=y;
y=aux%y;
}
return x;
}
void back(int x,int stare,long long cmmmc)
{
int semn=1,q;
if (x==k+1)
{
if (stare)
{
q=__builtin_popcount(stare);
if (!(q & 1))
semn=-1;
if (q>1)
rez+=n/cmmmc *(1<<(__builtin_popcount(stare)-1))*semn;
else
rez+=n/cmmmc;
}
return ;
}
long long cmmmc_nou;
cmmmc_nou=cmmmc/cmmdc(cmmmc,d[x]) * d[x];
if (cmmmc_nou<=n)
back(x+1,stare+(1<<(x-1)),cmmmc_nou);
back(x+1,stare,cmmmc);
}
int main()
{
int i;
in=fopen("light2.in","r");
out=fopen("light2.out","w");
fscanf(in,"%lld%d",&n,&k);
for (i=1;i<=k;i++)
fscanf(in,"%d",&d[i]);
back(1,0,1);
fprintf(out,"%lld\n",rez);
}