#K72422. Perfect Square Subarray

    ID: 33750 Type: Default 1000ms 256MiB

Perfect Square Subarray

Perfect Square Subarray

You are given an array of integers. Your task is to determine whether there exists a contiguous subarray such that the product of its elements is a perfect square. A number \(n\) is called a perfect square if there exists an integer \(k\) with \(n = k^2\). Note that negative numbers cannot be perfect squares (with the only exception that 0 is considered a perfect square since \(0 = 0^2\)).

The subarray must consist of consecutive elements from the array. For each test case, output YES if such a subarray exists, otherwise output NO.

inputFormat

The input is read from standard input (stdin) and has the following format:

T
n
a1 a2 ... an
... (repeated for each test case)

Where:

  • T: the number of test cases.
  • For each test case:
    • n: the number of elements in the array.
    • a1, a2, ..., an: the integers in the array.

outputFormat

For each test case, output a single line containing either YES if there exists a contiguous subarray whose product is a perfect square; otherwise, output NO. The output should be written to standard output (stdout).

## sample
4
3
1 2 3
4
4 -1 2 2
2
3 3
5
1 -2 3 6 -6
YES

YES YES YES

</p>