Perfect powers
Practice
4.5 (4 votes)
String algorithms
Algorithms
C++
Hashing algorithm
Problem
44% Success 741 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code
You are given an array \(A\) of \(N\) 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 \(x\) such that \(x^3 = P\) where \(P\) is the product of numbers in the subarray.
Input format
- The first line contains an integer \(T\) denoting the number of test cases.
- The first line of each test case contains an integer \(N\) denoting the number of elements in the array.
- The next line of each test case contains \(N\) 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
\(1 \le T \le 10\)
\(1 \le N \le 10^5\)
\(1 \le A[i] \le 100\)
Sample Input
1 5 27 1 2 4 2
Sample Output
7
Explanation
7 subarrays satisfy the given condition.
- [27]
- [27,1]
- [1]
- [2,4]
- [4,2]
- [1,2,4]
- [27,1,2,4]
Code Editor
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
Submissions
Please login to view your submissions
Similar Problems
Points:30
32 votes
Tags:
MediumHash functionStringHashing algorithm
Points:30
5 votes
Tags:
Hashing AlgorithmString AlgorithmsAlgorithms
Points:30
3 votes
Tags:
MediumAlgorithmsStringKMP AlgorithmHashing algorithm
Editorial
Login to unlock the editorial
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