Pagini recente » Monitorul de evaluare | Monitorul de evaluare | Cod sursa (job #544049) | Cod sursa (job #364531) | Cod sursa (job #1551618)
#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 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)
return;
if(k%2==0)
{
sol-=(1<<(k-1))*(N/cm);
}
else
sol+=(1<<(k-1))*(N/cm);
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();
Back(1,1);
g<<sol<<'\n';
return 0;
}