結果

問題 No.1146 土偶Ⅰ
ユーザー face4face4
提出日時 2020-08-05 19:32:41
言語 Java21
(openjdk 21)
結果
AC  
実行時間 71 ms / 2,000 ms
コード長 874 bytes
コンパイル時間 1,978 ms
コンパイル使用メモリ 75,484 KB
実行使用メモリ 54,128 KB
最終ジャッジ日時 2023-10-17 11:31:11
合計ジャッジ時間 4,606 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
51,476 KB
testcase_01 AC 54 ms
53,520 KB
testcase_02 AC 54 ms
53,520 KB
testcase_03 AC 58 ms
53,516 KB
testcase_04 AC 71 ms
54,088 KB
testcase_05 AC 59 ms
53,524 KB
testcase_06 AC 65 ms
53,520 KB
testcase_07 AC 70 ms
54,080 KB
testcase_08 AC 68 ms
53,524 KB
testcase_09 AC 60 ms
53,512 KB
testcase_10 AC 57 ms
53,524 KB
testcase_11 AC 65 ms
53,532 KB
testcase_12 AC 69 ms
54,088 KB
testcase_13 AC 54 ms
53,516 KB
testcase_14 AC 62 ms
52,472 KB
testcase_15 AC 70 ms
54,128 KB
testcase_16 AC 62 ms
53,528 KB
testcase_17 AC 54 ms
53,528 KB
testcase_18 AC 55 ms
53,520 KB
testcase_19 AC 61 ms
53,524 KB
testcase_20 AC 54 ms
53,516 KB
testcase_21 AC 56 ms
53,540 KB
testcase_22 AC 56 ms
53,524 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;

public class Main {
    static int gcd(int a, int b){
        return b == 0 ? a : gcd(b, a%b);
    }
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int a[] = new int[n];
        for(int i = 0; i < n; i++){
            a[i] = Integer.parseInt(br.readLine());
        }
        int ans = 0;
        for(int i = 0; i < n; i++){
            for(int j = i+1; j < n; j++){
                int g = gcd(a[i], a[j]);
                if(g == 1){
                    ans += n-j-1;
                    continue;
                }
                for(int k = j+1; k < n; k++){
                    ans += gcd(g, a[k])==1 ? 1 : 0;
                }
            }
        }
        System.out.println(ans);
    }
}
0