Four Multiples

View as PDF

Submit solution


Points: 100
Time limit: 1.0s
Memory limit: 250M

Problem type

How many integers in [1, n] are divisible by at least one of the four positive integers a, b, c, and d?

Print the exact count (not modulo anything).

Input

A single line containing five integers n, a, b, c, and d.

Output

Print one integer: the number of integers in [1, n] that are divisible by at least one of a, b, c, and d.

Constraints

  • 1 \le n \le 10^{18}
  • 1 \le a, b, c, d \le 10^9

Example 1

Input
10 2 3 5 7
Output
9
Explanation

The integers in [1, 10] divisible by 2, 3, 5, or 7 are 2, 3, 4, 5, 6, 7, 8, 9, 10. Only 1 is missing.

Example 2

Input
1 2 3 4 5
Output
0
Explanation

The only candidate is 1, and none of 2, 3, 4, 5 divide 1.

Example 3

Input
100 2 2 2 2
Output
50
Explanation

All four moduli are 2, so the answer is the number of even integers in [1, 100].


Comments

There are no comments at the moment.