#K2661. Beautiful Pairs

    ID: 24787 Type: Default 1000ms 256MiB

Beautiful Pairs

Beautiful Pairs

Given an array of integers, determine whether the array can form a Beautiful Pair. An array is called a Beautiful Pair if it contains at least two elements and there exists at least one pair of adjacent elements (after sorting the array in non-decreasing order) whose greatest common divisor (gcd) is greater than 1.

Formally, let \(S = [a_1,a_2,\dots,a_n]\) be an array with \(n \ge 2\). Let \(S'\) be the sorted version of \(S\). If there exists an index \(i\) (\(1 \leq i 1\), then the array is considered to have a Beautiful Pair. Otherwise, it is not.

For each test case, if the array forms a Beautiful Pair, output YES; otherwise, output NO.

Example:

Input:
3
4
6 9 15 25
3
3 5 7
5
18 24 30 12 36

Output: YES NO YES

</p>

inputFormat

The input starts with an integer t representing the number of test cases. Each test case consists of two lines: the first line contains an integer n (the number of elements in the array), and the second line contains n space-separated integers representing the array elements.

outputFormat

For each test case, output a single line: YES if the array forms a Beautiful Pair, otherwise NO.## sample

3
4
6 9 15 25
3
3 5 7
5
18 24 30 12 36
YES

NO YES

</p>