#include #include long long f(long long n1, long long n2) { long long wk1 = n1; long long wk2 = n2; while (1) { if (wk1 == wk2) { break; } if (wk1 < wk2) { wk1 += n1; } else { wk2 += n2; } } return wk1; } int main() { long long N; long long n[3] = {0}; long long cnt = 0; long long d[6] = {0}; std::cin >> N; std::cin >> n[0]; std::cin >> n[1]; std::cin >> n[2]; std::sort(&n[0], &n[3]); for (int i = 0; i < 3; i++) { if (n[i] == 0) { std::cout << -1 << std::endl; return 0; } if (n[i] == 1) { std::cout << N << std::endl; return 0; } } cnt += N / n[0]; if (n[0] != n[1]) { cnt += N / n[1]; } if (n[0] != n[2] && n[1] != n[2]) { cnt += N / n[2]; } d[0] = n[0]; d[1] = n[1]; d[2] = n[2]; while (1) { if (d[0] > N && d[1] > N && d[2] > N) { break; } if (d[0] == d[1] && d[1] == d[2] && d[2] == d[0]) { break; } d[3] = f(d[0], d[1]); if (d[3] < N) { cnt -= N / d[3]; } d[4] = f(d[1], d[2]); if (d[4] < N && d[3] != d[4]) { cnt -= N / d[4]; } d[5] = f(d[2], d[0]); if (d[5] < N && d[3] != d[5] && d[4] != d[5]) { cnt -= N / d[5]; } d[0] = f(d[3], d[4]); if (d[0] < N) { cnt += N / d[0]; } d[1] = f(d[4], d[5]); if (d[1] < N && d[0] != d[1]) { cnt += N / d[1]; } d[2] = f(d[5], d[3]); if (d[2] < N && d[0] != d[2] && d[1] != d[2]) { cnt += N / d[2]; } } std::cout << cnt << std::endl; return 0; }