Pagini recente » Cod sursa (job #1995439) | Cod sursa (job #1956935) | Cod sursa (job #1199858) | Cod sursa (job #571194) | Cod sursa (job #973067)
Cod sursa(job #973067)
#include <fstream>
using namespace std;
ifstream fin ("light2.in");
ofstream fout ("light2.out");
typedef long long int64;
int64 N; int M; int64 V[23];int64 Response;
void Read() {
fin >> N >> M;
for(int i = 1; i <= M; ++i)
fin >> V[i];
}
inline int64 GCD(int64 A,int64 B) {
int64 R;
while(B) {R = A % B; A = B; B = R;}
return A;
}
inline void Back(int pos, int64 Value, int64 op, int64 P) {
int64 T;
for(int i = pos + 1; i <= M; ++i) {
T = Value * V[i] / GCD(Value, V[i]);
Response += N / T * op * P;
Back(i, T, -op, P * 2);
}
}
void Print() {
fout << Response <<'\n';
}
int main() {
Read ();
for(int i = 1; i <= M; ++i){
Response += N / V[i];
Back(i , V[i], -1, 2);
}
Print ();
return 0;
}