Query multiples
Practice
4.1 (12 votes)
Approved
Binary search
Easy
Grammar Verified
Hiring
Math
Searching
Problem
51% Success 2604 Attempts 20 Points 1s Time Limit 64MB Memory 1024 KB Max Code

An array \(arr\) has indices numbered from 1 to N. You are given Q queries with two integers, \(i X\) in each.

Write a program to find the number of multiples of X in the array \(arr\) that falls between the \(i^{th} index and the end of the array.

Input format

  • First line: Two space-separated integers \)N\( and \)Q\(
  • Second line: \)N\( space-separated integers (denoting the array \)arr\()
  • Next \)Q\( lines: Two space-separated integers, \)i\( and \)X\(

Output format

For each query, print the number of multiples of \)X\( in the array \)arr\( that falls between the \)i^{th} index and the end of the array.

Constraints

\(1 ≤ N ≤ 10^5\)
\(1 ≤ Q ≤ 10^5\)
\(1 ≤ X ≤ 20000\)
\(1 ≤ arr[i] ≤ 20000\)

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:20
38 votes
Tags:
ApprovedBinary SearchData StructuresEasyHash MapsHashing AlgorithmOpenSorting
Points:20
15 votes
Tags:
AlgorithmsBinary SearchEasySearchingTwo pointer
Points:20
272 votes
Tags:
Binary SearchEasyOpenSorting