Square or Cube

3.2

5 votes
Hash function, Number Theory, Algorithms, Medium-Hard, String, Hashing algorithm
Problem

You have an array A consisting of n integers. You will be given q queries.

In each query, you will be given two integers l and r which denotes two positions of the array. P is the product of all the integers between lth and rth positions. We can write P=ri=lAi

For each query you have to determine whether P is a square or cube or both of them or none of them.

Input:

First line will contain two integers n(1n300000) and q(1q300000).

Next line will contain n integers where ith(1in) of them represents Ai(105Ai105).

Each of the next q lines will contain two positive integers l and r.

Output:

For each query print

"Square" if P is only a square number

"Cube" if P is only a cubic number

"Both" if P is both square and cube

otherwise "None".

Sample Input
7 5
2 4 16 -4 5 5 7
1 2
2 3
3 4
5 6
6 7
Sample Output
Cube
Both
Cube
Square
None
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Query 1: Product = 2×4=8 is a cube.

Query 2: Product = 4×16=64 is both square and cube.

Query 3: Product = 16×(4)=64 is a cube.

Query 4: Product = 5×5=25 is a square.

Query 5: Product = 5×7=35 is neither a square nor a cube.

Contributers:
Editor Image

?