Count Numbers
Practice
3.7 (11 votes)
Algorithms
Approved
Math
Medium
Open
Problem
53% Success 4401 Attempts 30 Points 2s Time Limit 256MB Memory 1024 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

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...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
4 votes
Tags:
CombinatoricsDynamic ProgrammingBasic ProgrammingNumber theoryMathInclusion-exclusion
Points:30
1 votes
Tags:
CombinatoricsInclusion-ExclusionMathMedium
Points:30
6 votes
Tags:
ApprovedMathMedium