Divide and Rule 2.0
Time limit1sMemory limit1024 MB
Given an array of distinct values, count the positions in each query range [l, r] whose value divides d or is a multiple of d.
- Level
Hard8 of 10
- Topics
- Number theory, Prefix sum, Array
- Solved
- No attempts yet
Problem
Sasha loves the division operation so much that he invented a problem for the autumn informatics tournament that uses only division. The problem gives him a favorite array of positive integers and queries. The -th query is given by three positive integers , , and . For each query, count the numbers at positions through in the array that are divisors of or multiples of . Time is running out, and you want first place, so write a program divide.cpp that answers the queries.
Input
The first line contains the integers and . The second line contains integers . Each of the following lines contains , , and .
Output
Print one line with integers. The -th integer is the answer to the -th query.
Constraints
, , . For all , .