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
Submissions
Please login to view your submissions
Similar Problems
Points:30
5 votes
Tags:
ApprovedDepth First SearchInclusion ExclusionInclusion exclusion principleMathMediumMobius Function
Points:30
1 votes
Tags:
CombinatoricsInclusion-ExclusionMathMedium
Points:30
6 votes
Tags:
ApprovedMathMedium
Editorial