結果

問題 No.1036 Make One With GCD 2
ユーザー ks2mks2m
提出日時 2020-04-24 22:35:32
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,354 ms / 2,000 ms
コード長 1,009 bytes
コンパイル時間 1,923 ms
コンパイル使用メモリ 73,876 KB
実行使用メモリ 158,296 KB
最終ジャッジ日時 2023-10-14 19:28:32
合計ジャッジ時間 36,322 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 755 ms
152,548 KB
testcase_01 AC 1,354 ms
156,584 KB
testcase_02 AC 744 ms
153,628 KB
testcase_03 AC 401 ms
95,044 KB
testcase_04 AC 455 ms
113,180 KB
testcase_05 AC 41 ms
49,096 KB
testcase_06 AC 40 ms
49,336 KB
testcase_07 AC 670 ms
102,424 KB
testcase_08 AC 560 ms
86,776 KB
testcase_09 AC 775 ms
142,812 KB
testcase_10 AC 722 ms
141,440 KB
testcase_11 AC 767 ms
144,004 KB
testcase_12 AC 747 ms
139,264 KB
testcase_13 AC 1,321 ms
150,580 KB
testcase_14 AC 1,351 ms
151,380 KB
testcase_15 AC 1,301 ms
154,628 KB
testcase_16 AC 1,316 ms
155,956 KB
testcase_17 AC 1,322 ms
149,764 KB
testcase_18 AC 75 ms
51,032 KB
testcase_19 AC 75 ms
52,212 KB
testcase_20 AC 91 ms
54,792 KB
testcase_21 AC 100 ms
52,840 KB
testcase_22 AC 1,284 ms
153,588 KB
testcase_23 AC 1,103 ms
131,528 KB
testcase_24 AC 1,326 ms
148,164 KB
testcase_25 AC 1,263 ms
158,296 KB
testcase_26 AC 1,303 ms
149,816 KB
testcase_27 AC 42 ms
49,836 KB
testcase_28 AC 42 ms
49,732 KB
testcase_29 AC 41 ms
49,616 KB
testcase_30 AC 42 ms
49,580 KB
testcase_31 AC 47 ms
49,756 KB
testcase_32 AC 47 ms
49,680 KB
testcase_33 AC 41 ms
49,484 KB
testcase_34 AC 46 ms
49,724 KB
testcase_35 AC 40 ms
49,536 KB
testcase_36 AC 42 ms
49,544 KB
testcase_37 AC 41 ms
49,532 KB
testcase_38 AC 739 ms
154,728 KB
testcase_39 AC 725 ms
154,396 KB
testcase_40 AC 1,121 ms
131,360 KB
testcase_41 AC 1,195 ms
155,224 KB
testcase_42 AC 1,173 ms
154,980 KB
testcase_43 AC 1,279 ms
155,104 KB
testcase_44 AC 1,272 ms
155,308 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] sa = br.readLine().split(" ");
		BigInteger[] a = new BigInteger[n];
		for (int i = 0; i < n; i++) {
			a[i] = new BigInteger(sa[i]);
		}
		br.close();

		long ans = 0;
		BigInteger now = BigInteger.ZERO;
		int l = 0;
		for (int r = 0; r < n; r++) {
			now = now.gcd(a[r]);
			if (now.compareTo(BigInteger.ONE) == 0) {
				BigInteger now2 = a[r];
				for (int k = r; k >= l; k--) {
					BigInteger next = now2.gcd(a[k]);
					if (next.compareTo(BigInteger.ONE) == 0) {
						ans += (long) (n - r) * (k - l + 1);
						l = k + 1;
						if (l > r) {
							now = BigInteger.ZERO;
						} else {
							now = now2;
						}
						break;
					}
					now2 = next;
				}
			}
		}
		System.out.println(ans);
	}
}
0