Pagini recente » Cod sursa (job #2320040) | Cod sursa (job #1021731) | Cod sursa (job #207339) | Cod sursa (job #1194238) | Cod sursa (job #1799674)
#include <fstream>
using namespace std;
ifstream fin("light2.in");
ofstream fout("light2.out");
typedef long long i64;
const int kmax= 22;
i64 n, sol;
int k;
int v[kmax+1];
i64 gcd( i64 x, i64 y ) {
if ( y==0 )
return x;
return gcd(y, x%y);
}
void backt( int x, int nr, i64 aux ) {
if ( x==k+1 ) {
if ( nr%2==0 && nr>0 ) {
sol= sol-n/aux*(1<<(nr-1));
} else if ( nr%2==1 ) {
sol= sol+n/aux*(1<<(nr-1));
}
} else {
backt(x+1, nr, aux);
i64 cmmmc= (i64)aux/gcd(aux, v[x])*v[x];
if ( cmmmc<=n ) {
backt(x+1, nr+1, cmmmc);
}
}
}
int main( ) {
fin>>n>>k;
for ( int i= 1; i<=k; ++i ) {
fin>>v[i];
}
backt(1, 0, 1);
fout<<sol<<"\n";
return 0;
}