B - Geometric Sequence
Source: atcoder
Difficulty: 200

Problem Statement
You are given a length-
N
sequence
A=(A_1,A_2,\ldots,A_N)
of positive integers.
Determine whether
A
is a geometric progression.
Constraints
2 \leq N \leq 100
1 \leq A_i \leq 10^9
All input values are integers.
Input
The input is given from Standard Input in the following format:
N
A_1
A_2
\ldots
A_N
Output
If
A
is a geometric progression, print
Yes
; otherwise, print
No
.
Sample Input 1
5
3 6 12 24 48
Sample Output 1
Yes
A=(3,6,12,24,48)
.
A
is a geometric progression with first term
3
, common ratio
2
, and five terms.
Therefore, print
Yes
.
Sample Input 2
3
1 2 3
Sample Output 2
No
A=(1,2,3)
.
Since
A_1 : A_2 = 1 : 2 \neq 2 : 3 = A_2 : A_3
,
A
is not a geometric progression.
Therefore, print
No
.
Sample Input 3
2
10 8
Sample Output 3
Yes
A
is a geometric progression with first term
10
, common ratio
0.8
, and two terms.
Therefore, print
Yes
.

C++ solution:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main()
{
    int N;
    cin >> N;
    vector<ll> A(N, 0);
    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
    }
    bool beCommonRatio = true;

    for (int i = 0; i < N - 2; i++) {
        if ((A.at(i) * A.at(i + 2) != A.at(i + 1) * A.at(i + 1))) {
            beCommonRatio = false;
            cout << "No" << endl;
            break;
        }
    }
    if (beCommonRatio) {
        cout << "Yes" << endl;
    }


}

Go solution:
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
var wr = bufio.NewWriter(os.Stdout)

func out(x ...interface{}) {
	fmt.Fprintln(wr, x...)
}

func outSlice[T any](s []T) {
	for i := 0; i < len(s)-1; i++ {
		fmt.Fprint(wr, s[i], " ")
	}
	fmt.Fprintln(wr, s[len(s)-1])
}

func getI() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getF() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getI()
	}
	return ret
}

func getS() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

// min for n entry
func nmin(a ...int) int {
	ret := a[0]
	for _, e := range a {
		ret = min(ret, e)
	}
	return ret
}

// max for n entry
func nmax(a ...int) int {
	ret := a[0]
	for _, e := range a {
		ret = max(ret, e)
	}
	return ret
}

func chmin(a *int, b int) bool {
	if *a < b {
		return false
	}
	*a = b
	return true
}

func chmax(a *int, b int) bool {
	if *a > b {
		return false
	}
	*a = b
	return true
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func gdc(a, b int) int {
	if b == 0 {
		return a
	}
	return gdc(b, a%b)
}

func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, math.MaxInt32)
	// this template is new version.
	// use getI(), getS(), getInts(), getF()
	N := getI()
	a := getInts(N)

	for i := 2; i < N; i++ {
		if a[i]*a[0] != a[i-1]*a[1] {
			out("No")
			return
		}
	}
	out("Yes")
}

Java solution:
import java.util.*;
import java.io.*;
import java.math.BigDecimal;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int N = Integer.parseInt(br.readLine());
        StringTokenizer st = new StringTokenizer(br.readLine());

        List<Long> list = new ArrayList<>();
        while (st.hasMoreTokens()) {
            list.add(Long.parseLong(st.nextToken()));
        }

        for (int i = 0; i < N - 2; i++) {
            if (list.get(i+1) * list.get(i+1) != list.get(i) * list.get(i + 2)) {
                System.out.println("No");
                return;
            }
        }
        System.out.println("Yes");
    }
}

JavaScript solution:
function Main(input) {
  const inputs = input.split("\n")
  const N = Number(inputs[0])
  const a_arr = inputs[1].split(" ").map((a) => BigInt(a))
  if (N <= 2) {
    console.log("Yes")
    return
  }
  for (let i = 0; i < N - 2; i++) {
    if (a_arr[i ] * a_arr[i + 2] !== a_arr[i+1] * a_arr[i+1]) {
      console.log("No")
      return
    }
  }
  console.log("Yes")
}
Main(require("fs").readFileSync(0) + "")
// Main(`5
// 3 6 12 24 48
// `)

// Main(`3
// 1 2 3
// `)

// Main(`2
// 10 8
// `)

Python solution:
n = int(input())
s = list(map(int,input().split()))
flag = False
for i in range(n-2):
  if s[i] * s[i+2] != s[i+1]*s[i+1]:
    flag = True

if not flag:
  print("Yes")
else:
  print("No")

Ruby solution:
N = gets.to_i
A = gets.split.map(&:to_i)

r = A[1] / A[0].to_r
2.upto(N - 1) do |i|
  if r * A[i - 1] != A[i]
    puts "No"
    exit
  end
end

puts "Yes"