Perfect powers

4.5

4 votes
String Algorithms, Algorithms, C++, Hashing Algorithm
Problem

You are given an array of integers. Find the number of subarrays that satisfy the following condition:

  • The product of numbers in the subarray is a perfect cube, that is, there exists a positive integer such that  where is the product of numbers in the subarray.

Input format

  • The first line contains an integer denoting the number of test cases.
  • The first line of each test case contains an integer  denoting the number of elements in the array.
  • The next line of each test case contains space-separated integers denoting the array elements.

Output format

For each test case, print the number of subarrays that satisfy the provided condition in a new line.

Constraints

 

Sample Input
1
5
27 1 2 4 2
Sample Output
7
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

7 subarrays satisfy the given condition.

  • [27]
  • [27,1]
  • [1]
  • [2,4]
  • [4,2]
  • [1,2,4]
  • [27,1,2,4]
Editor Image

?