Pagini recente » Cod sursa (job #1925458) | Cod sursa (job #1778295) | Cod sursa (job #1941228) | Cod sursa (job #427919) | Cod sursa (job #1344361)
#include <iostream>
#include <fstream>
#define LL long long int
using namespace std;
LL N,d[30],sum; int K,P;
inline LL gcd(LL a, LL b){
if (!b) return a;
return gcd(b,a%b);
}
void comb(int cnt, int ind, LL aux){
if (aux>N || aux<0) return;
if (ind>K){
if (cnt==0) return;
if (cnt%2) sum+=(1<<(cnt-1))*(N/aux);
else sum-=(1<<(cnt-1))*(N/aux);
return;
}
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;
for (i=1; i<=K; i++) fin >> d[i];
comb(0,1,1);
fout << sum;
return 0;
}