Pagini recente » Cod sursa (job #1584616) | Cod sursa (job #2944563) | Cod sursa (job #1232609) | Cod sursa (job #41621) | Cod sursa (job #541579)
Cod sursa(job #541579)
#include <algorithm>
#include <fstream>
using namespace std;
const char Input[] = "light2.in";
const char Output[] = "light2.out";
const int MaxK = 23;
int K;
int d[MaxK];
long long int N, XXX;
long long int pow2[MaxK];
inline long long int CMMDC( long long int a, long long int b ) {
int r;
do {
r = a % b;
a = b;
b = r;
}
while( r );
return a;
}
int main() {
ifstream fin( Input );
ofstream fout( Output );
int i, j, cnt;
long long int aux;
fin >> N >> K;
for( i = 1; i <= K; ++i )
fin >> d[i];
pow2[0] = 1;
for( i = 1; i <= K; ++i )
pow2[i] = (pow2[i - 1] << 1);
for( i = 1; i < pow2[K]; ++i ) {
aux = 1;
cnt = 0;
for( j = 1; j <= K; ++j )
if( pow2[j - 1] & i ) {
aux = aux * d[j] / CMMDC( aux, d[j] );
++cnt;
}
if( cnt & 1 )
XXX += pow2[cnt - 1] * (N / aux);
else
XXX -= pow2[cnt - 1] * (N / aux);
}
fout << XXX;
fin.close();
fout.close();
return 0;
}