给一个序列判断其是否是等比数列,每个数字A[i]不小于100位
(1)存在0的时候要全都是0,才能是Yes,存在0但不全是0则是No
(2)不存在0,则A[i-1]*A[i+1]==A[i]*A[i]是否全都成立
my code
import java.math.*;
import java.io.*;
import java.util.*;
class InputReader {
private InputStream stream;
private byte[] buf = new byte[1000];
private int curChar;
private int numChars;
public InputReader(InputStream stream) {
this.stream = stream;
}
private int read() {
if (numChars == -1)
throw new UnknownError();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new UnknownError();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public int readInt() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public int[] readIntArray(int length) {
int[] res = new int[length];
for (int i = 0; i < length; i++)
res[i] = readInt();
return res;
}
public int[][] readIntArray(int n, int m) {
int[][] res = new int[n][m];
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
res[i][j] = readInt();
return res;
}
public long readLong() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public long[] readLongArray(int length) {
long[] res = new long[length];
for (int i = 0; i < length; i++)
res[i] = readLong();
return res;
}
public long[][] readLongArray(int n, int m) {
long[][] res = new long[n][m];
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
res[i][j] = readLong();
return res;
}
public String readString() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuffer res = new StringBuffer();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public String[] readStringArray(int length) {
String[] res = new String[length];
for (int i = 0; i < length; i++)
res[i] = readString();
return res;
}
public String next() {
return readString();
}
private String readLine0() {
StringBuffer buf = new StringBuffer();
int c = read();
while (c != '\n' && c != -1) {
buf.appendCodePoint(c);
c = read();
}
return buf.toString();
}
public String readLine() {
String s = readLine0();
while (s.trim().length() == 0)
s = readLine0();
return s;
}
public String readLine(boolean ignoreEmptyLines) {
if (ignoreEmptyLines)
return readLine();
else
return readLine0();
}
public BigInteger readBigInteger() {
try {
return new BigInteger(readString());
} catch (NumberFormatException e) {
throw new InputMismatchException();
}
}
public char readCharacter() {
int c = read();
while (isSpaceChar(c))
c = read();
return (char) c;
}
public char[] readCharArray(int length) {
char[] res = new char[length];
for (int i = 0; i < length; i++)
res[i] = readCharacter();
return res;
}
public char[][] readCharArray(int n, int m) {
char[][] res = new char[n][m];
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
res[i][j] = readCharacter();
return res;
}
public double readDouble() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
double res = 0;
while (!isSpaceChar(c) && c != '.') {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
if (c == '.') {
c = read();
double m = 1;
while (!isSpaceChar(c)) {
if (c < '0' || c > '9')
throw new InputMismatchException();
m /= 10;
res += (c - '0') * m;
c = read();
}
}
return res * sgn;
}
public double[] readDoubleArray(int length) {
double[] res = new double[length];
for (int i = 0; i < length; i++)
res[i] = readDouble();
return res;
}
public double[][] readDoubleArray(int n, int m) {
double[][] res = new double[n][m];
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
res[i][j] = readDouble();
return res;
}
private boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
}
public class Main {
static InputReader cin = new InputReader(System.in);
static BigDecimal[] a = new BigDecimal[105];
static int n;
static boolean judge() {
if (n == 1)
return true;
int cnt = 0;
for (int i = 1; i <= n; i++) {
if (a[i].compareTo(BigDecimal.ZERO) == 0)
cnt++;
}
if (cnt > 0) {
if (cnt == n)
return true;
else
return false;
}
for (int i = 2; i < n; i++) {
BigDecimal x = a[i].multiply(a[i]);
BigDecimal y = a[i - 1].multiply(a[i + 1]);
if (x.compareTo(y) != 0)
return false;
}
return true;
}
public static void main(String[] args) throws IOException {
int T;
T = cin.readInt();
while (T-- > 0) {
n = cin.readInt();
for (int i = 1; i <= n; i++) {
a[i] = new BigDecimal(cin.next());
}
System.out.println(judge() ? "Yes" : "No");
}
}
}