Pagini recente » Cod sursa (job #1428201) | Cod sursa (job #179016) | Cod sursa (job #145235) | Cod sursa (job #147198) | Cod sursa (job #1343833)
#include <iostream>
#include <fstream>
#define LL long long int
using namespace std;
LL N,d[30],sum; int K,P;
LL gcd(LL a, LL b){
if (!b) return a;
return gcd(b,a%b);
}
void comb(int cnt, int ind, LL aux){
if (cnt==0){
sum+=N/aux;
return;
}
if (aux>N) return;
if (K-ind+1>cnt)
comb(cnt,ind+1,aux);
comb(cnt-1,ind+1,aux*d[ind]/gcd(aux,d[ind]));
}
int main(){
ifstream fin("light2.in");
ofstream fout("light2.out");
fin >> N >> K;
LL i,res=0;
for (i=1; i<=K; i++) fin >> d[i];
for (i=1; i<=K; i++){
sum=0;
comb(i,1,1);
if (i%2) res+=(1<<(i-1))*sum;
else res-=(1<<(i-1))*sum;
}
fout << res;
return 0;
}