Pagini recente » Cod sursa (job #3147921) | Cod sursa (job #968138) | Cod sursa (job #722300) | Cod sursa (job #2228205) | Cod sursa (job #1551622)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream f("light2.in");
ofstream g("light2.out");
long long N,K;
long long D[25],x[25],cm=1,sol;
long long Power[25];
long long CMMDC(long long a,long long b)
{
long long r=a%b;
while(r!=0)
{
a=b;
b=r;
r=a%b;
}
return b;
}
void Back(long long k,long long cm)
{
for(int i=x[k-1]+1;i<=K;i++)
{
x[k]=i;
long long aux=cm;
cm=(cm*D[x[k]])/CMMDC(cm,D[x[k]]);
if(cm>N)
{
cm=aux;
continue;
}
if(k%2==0)
{
sol-=(N/cm)*Power[k-1];
}
else
sol+=(N/cm)*Power[k-1];
if(k<K)
Back(k+1,cm);
cm=aux;
}
}
void Read()
{
f>>N>>K;
for(int i=1;i<=K;i++)
f>>D[i];
sort(D+1,D+K+1);
}
int main()
{
Read();
Power[0]=1;
for(int i=1;i<=K;i++)
Power[i]=Power[i-1]*2;
Back(1,1);
g<<sol<<'\n';
return 0;
}