Pagini recente » Cod sursa (job #1592924) | Cod sursa (job #2371331) | Cod sursa (job #1666348) | Cod sursa (job #1623689) | Cod sursa (job #2241017)
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll INF = 1e18;
const int MAXK = 21;
inline ll gcd(ll a, ll b) {
ll r;
while(b > 0) {
r = a % b;
a = b;
b = r;
}
return a;
}
int d[MAXK], k;
ll dp[1 << MAXK], n;
void bkt(int bit, int conf, ll val) {
if(bit == k) {
dp[conf] = n / val;
}
else {
bkt(bit + 1, conf, val);
val /= gcd(d[bit], val);
if(INF / val >= d[bit])
bkt(bit + 1, conf ^ (1 << bit), val * d[bit]);
}
}
int main() {
FILE *fi, *fout;
int i;
fi = fopen("light2.in" ,"r");
fout = fopen("light2.out" ,"w");
fscanf(fi,"%lld %d " ,&n,&k);
for(i = 0; i < k; i++) {
fscanf(fi,"%d " ,&d[i]);
}
bkt(0, 0, 1);
for(i = 0; i < k; i++) {
for(int conf = (1 << k) - 1; conf > 0; conf--) {
if(conf & (1 << i)) {
dp[conf ^ (1 << i)] -= dp[conf];
}
}
}
ll ans = 0;
for(int conf = 1; conf < (1 << k); conf++) {
if(__builtin_popcount(conf) & 1) {
ans += dp[conf];
}
}
fprintf(fout,"%lld" ,ans);
fclose(fi);
fclose(fout);
return 0;
}