MCPcopy Create free account
hub / github.com/E869120/math-algorithm-book / main

Method main

editorial/chap3-2/prob3-2-2.java:4–20  ·  view source on GitHub ↗
(String[] args)

Source from the content-addressed store, hash-verified

2
3class Main {
4 public static void main(String[] args) {
5 Scanner sc = new Scanner(System.in);
6
7 // 入力
8 int N = sc.nextInt();
9 long[] A = new long[N + 1];
10 for (int i = 1; i <= N; i++) A[i] = sc.nextLong();
11
12 // 答えを求める
13 long R = GCD(A[1], A[2]);
14 for (int i = 3; i <= N; i++) {
15 R = GCD(R, A[i]);
16 }
17
18 // 出力
19 System.out.println(R);
20 }
21 static long GCD(long A, long B) {
22 // 正の整数 A と B の最大公約数を返す関数
23 while (A >= 1 && B >= 1) {

Callers

nothing calls this directly

Calls 1

GCDMethod · 0.95

Tested by

no test coverage detected