Mai intai trebuie sa te autentifici.
Cod sursa(job #973045)
| Utilizator | Data | 13 iulie 2013 11:36:44 | |
|---|---|---|---|
| Problema | Light2 | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.86 kb |
#include <fstream>
using namespace std;
ifstream fin ("light2.in");
ofstream fout ("light2.out");
typedef long long int64;
int64 N; int M; int V[25];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;
}
void Back(int pos, int64 Value, int op, int Pow) {
int64 T;
for(int i = pos + 1; i <= M; ++i) {
T = Value * V[i] / GCD(V[i], Value);
Response += (N / T) * op * Pow;
Back(pos + 1, T, -op, (Pow << 1));
}
}
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;
}
