The Market
Practice
4.2 (12 votes)
Approved
Data structures
Dynamic programming
Medium
Segment trees
Sieve
Approved
Problem
55% Success 2299 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

There are N items in a market (indexed from 1 to N) each having a particular cost. The danger value of each item is given by the following pseudo code:

           Danger(cost) {
              danger_val = 0
              for ( each i from 1 to cost) {
                   if( cost modulo i is 0  ) {
                       increase danger_val by 1
                   }
              }
              return danger_val
          }

You are given Q queries which contain a range of items.

You need to find the number of pairs of items that have the same danger value.

Input format

  • First line of the input contains a single integer N
  • Second line of the input contains N space-separated integers denoting the prices of the items.
  • Third line of the input contains a single integer Q denoting the number of queries
  • Each of the next Q lines contain two space-separated integers L and R denoting the range of the items.

Output format

For each query, print the number of pairs of items that have the same danger value.

Constraints

  • \(1 ≤ N,Q ≤ 10^{5}\)
  • \(1 ≤ L ≤ R ≤ N\)
  • \(1 ≤ cost\ of\ item ≤ 10^{6}\)

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
8 votes
Tags:
ApprovedMathMediumOpenTrees
Points:30
5 votes
Tags:
Medium
Points:30
6 votes
Tags:
Advanced Data StructuresData StructuresMediumSegment Trees