結果

問題 No.1146 土偶Ⅰ
ユーザー tentententen
提出日時 2020-10-09 07:49:18
言語 Java21
(openjdk 21)
結果
AC  
実行時間 129 ms / 2,000 ms
コード長 707 bytes
コンパイル時間 2,163 ms
コンパイル使用メモリ 72,740 KB
実行使用メモリ 57,960 KB
最終ジャッジ日時 2023-09-27 12:31:29
合計ジャッジ時間 5,606 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 107 ms
56,100 KB
testcase_01 AC 103 ms
53,632 KB
testcase_02 AC 107 ms
55,620 KB
testcase_03 AC 112 ms
55,880 KB
testcase_04 AC 128 ms
56,036 KB
testcase_05 AC 113 ms
56,068 KB
testcase_06 AC 121 ms
55,612 KB
testcase_07 AC 126 ms
53,976 KB
testcase_08 AC 126 ms
56,052 KB
testcase_09 AC 116 ms
56,096 KB
testcase_10 AC 113 ms
55,780 KB
testcase_11 AC 122 ms
55,820 KB
testcase_12 AC 129 ms
55,988 KB
testcase_13 AC 110 ms
57,960 KB
testcase_14 AC 119 ms
56,156 KB
testcase_15 AC 123 ms
55,772 KB
testcase_16 AC 122 ms
55,892 KB
testcase_17 AC 103 ms
55,712 KB
testcase_18 AC 109 ms
56,040 KB
testcase_19 AC 120 ms
56,016 KB
testcase_20 AC 106 ms
55,928 KB
testcase_21 AC 117 ms
55,984 KB
testcase_22 AC 115 ms
55,748 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
		    arr[i] = sc.nextInt();
		}
		int count = 0;
		for (int i = 0; i < n - 2; i++) {
		    for (int j = i + 1; j < n - 1; j++) {
		        int gcd = getGCD(arr[i], arr[j]);
		        for (int k = j + 1; k < n; k++) {
		            if (getGCD(gcd, arr[k]) == 1) {
		                count++;
		            }
		        }
		    }
		}
		System.out.println(count);
	}
	
	static int getGCD(int x, int y) {
	    if (x % y == 0) {
	        return y;
	    } else {
	        return getGCD(y, x % y);
	    }
	}
}
0