Query multiples

4.1

12 votes
Approved, Binary Search, Easy, Grammar-Verified, Hiring, Math, Searching
Problem

An array arr has indices numbered from 1 to N. You are given Q queries with two integers, iX 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

1N105
1Q105
1X20000
1arr[i]20000

Time Limit: 1
Memory Limit: 64
Source Limit:
Explanation

There are two numbers, 6 and 2, after the index 2 divisible by 2.

Editor Image

?