結果

問題 No.1036 Make One With GCD 2
ユーザー ks2mks2m
提出日時 2020-04-24 22:32:16
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,245 ms / 2,000 ms
コード長 1,011 bytes
コンパイル時間 5,313 ms
コンパイル使用メモリ 74,184 KB
実行使用メモリ 123,576 KB
最終ジャッジ日時 2023-10-14 19:26:37
合計ジャッジ時間 34,412 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 588 ms
118,864 KB
testcase_01 AC 1,206 ms
115,604 KB
testcase_02 AC 500 ms
120,836 KB
testcase_03 AC 281 ms
73,736 KB
testcase_04 AC 374 ms
80,796 KB
testcase_05 AC 41 ms
49,312 KB
testcase_06 AC 42 ms
49,280 KB
testcase_07 AC 456 ms
77,396 KB
testcase_08 AC 438 ms
71,000 KB
testcase_09 AC 694 ms
114,020 KB
testcase_10 AC 676 ms
104,384 KB
testcase_11 AC 722 ms
113,860 KB
testcase_12 AC 700 ms
109,740 KB
testcase_13 AC 1,226 ms
119,436 KB
testcase_14 AC 1,233 ms
117,068 KB
testcase_15 AC 1,185 ms
123,204 KB
testcase_16 AC 1,196 ms
123,368 KB
testcase_17 AC 1,200 ms
118,092 KB
testcase_18 AC 63 ms
50,564 KB
testcase_19 AC 70 ms
51,720 KB
testcase_20 AC 85 ms
54,796 KB
testcase_21 AC 85 ms
52,324 KB
testcase_22 AC 1,200 ms
122,220 KB
testcase_23 AC 1,022 ms
100,800 KB
testcase_24 AC 1,245 ms
117,820 KB
testcase_25 AC 1,155 ms
122,416 KB
testcase_26 AC 1,221 ms
123,576 KB
testcase_27 AC 43 ms
49,796 KB
testcase_28 AC 44 ms
49,360 KB
testcase_29 AC 43 ms
49,484 KB
testcase_30 AC 45 ms
49,564 KB
testcase_31 AC 49 ms
49,572 KB
testcase_32 AC 51 ms
50,144 KB
testcase_33 AC 44 ms
49,840 KB
testcase_34 AC 50 ms
49,672 KB
testcase_35 AC 45 ms
50,208 KB
testcase_36 AC 45 ms
49,660 KB
testcase_37 AC 44 ms
49,516 KB
testcase_38 AC 524 ms
119,784 KB
testcase_39 AC 639 ms
121,044 KB
testcase_40 AC 991 ms
101,044 KB
testcase_41 AC 997 ms
121,624 KB
testcase_42 AC 981 ms
120,100 KB
testcase_43 AC 1,014 ms
119,372 KB
testcase_44 AC 982 ms
119,400 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(" ");
		long[] a = new long[n];
		for (int i = 0; i < n; i++) {
			a[i] = Long.parseLong(sa[i]);
		}
		br.close();

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

	static long gcd(long a, long b) {
		return BigInteger.valueOf(a).gcd(BigInteger.valueOf(b)).longValue();
	}
}
0