Get The Count

4

6 votes
Data Structures, Binary Search, Sparse Table, Sparse table, Algorithms, Implementation, Advanced Data Structures, Math
Problem

You are given an array A of size N. You are also given two integers X and Y. Your task is to find the count of subarrays whose least common multiple (LCM) value is between X and Y (inclusive).

The subarray of A is a contiguous part of the array A, i. e. the array Ai,Ai+1,....,Aj for some 1ijN.

 Input Format:

  • The first line contains a single integer T, which denotes the number of test cases.
  • For each test case:
    • The first line contains denoting the size of the array A.
    • The second line contains N space-separated integers, denoting the elements of A.
    • The third line contains 2 space-separated integers, denoting the values X and Y.

Output Format:

For each test case, print the count of subarrays within the given array such that the least common multiple (LCM) of all elements in the subarray is between X and Y (inclusive) in a new line.

Constraints:

1T1051N2×1051A[i]109  i[1,N]1XY109The sum of all values of N over all test cases doesn't exceed 2×105

Time Limit: 3
Memory Limit: 256
Source Limit:
Explanation

Explanation

For test case 1:

  • N = 5
  • A = [2, 4, 5, 2, 3]
  • X = 4
  • Y = 7

In the given array there are the following 4 subarrays with their least common multiple (LCM) values between (=4) & (=7):

  • [2, 4]
  • [4]
  • [5]
  • [2, 3]

Thus, the answer is 4.

Editor Image

?