#K53317. Geometric Progression Rearrangement
Geometric Progression Rearrangement
Geometric Progression Rearrangement
You are given an array of N integers. Your task is to determine whether the elements of the array can be rearranged to form a geometric progression. In other words, check if there exists an ordering of the array such that for some non-zero starting value \(a\) and a common ratio \(r\), the sequence is:
\(a, ar, ar^2, \dots, ar^{N-1}\)
Note: A geometric progression is only valid if the first term \(a \neq 0\) and the ratio is well-defined. Also, for this problem, an array with fewer than 2 elements is not considered a valid geometric progression.
inputFormat
The first line of input contains a positive integer N
, the number of elements in the array.
The second line contains N
space-separated integers.
outputFormat
Output a single line: True
if the array can be rearranged to form a geometric progression; otherwise, output False
.
4
2 6 18 54
True