Count Numbers
53% Success4407 Attempts30 Points2s Time Limit256MB Memory1024 KB Max Code
Given K prime numbers and T queries of form Ai, Bi, for each query print the number of integers between Ai and Bi (both inclusive) that are divisible by atleast one of the K given primes.
Input
First line: K and T.
Second line: K primes.
Next T lines, each contain Ai, Bi.
Output
Print T lines, denoting the answer to each of the T queries.
Constraints
1 ≤ K ≤ 10
1 ≤ T ≤ 100
1 ≤ A ≤ B ≤ 109
Each prime ≤ 107
Examples
Input
2 1 2 3 1 10
Output
7
Explanation
2,3,4,6,8,9,10 are the 7 numbers.
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Loading Editor...
Results