結果

問題 No.1036 Make One With GCD 2
ユーザー neterukunneterukun
提出日時 2020-04-24 22:21:42
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 761 bytes
コンパイル時間 177 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 191,064 KB
最終ジャッジ日時 2024-04-24 17:49:59
合計ジャッジ時間 19,413 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 563 ms
187,356 KB
testcase_01 AC 226 ms
173,504 KB
testcase_02 AC 263 ms
159,380 KB
testcase_03 AC 79 ms
93,952 KB
testcase_04 AC 114 ms
122,240 KB
testcase_05 AC 36 ms
51,840 KB
testcase_06 AC 39 ms
52,352 KB
testcase_07 AC 123 ms
102,784 KB
testcase_08 AC 102 ms
103,936 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 49 ms
62,592 KB
testcase_19 AC 49 ms
62,720 KB
testcase_20 AC 49 ms
63,232 KB
testcase_21 AC 50 ms
62,848 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 36 ms
51,968 KB
testcase_28 AC 35 ms
52,096 KB
testcase_29 AC 39 ms
52,224 KB
testcase_30 AC 40 ms
51,968 KB
testcase_31 AC 38 ms
52,480 KB
testcase_32 AC 37 ms
52,480 KB
testcase_33 AC 39 ms
51,968 KB
testcase_34 AC 39 ms
52,224 KB
testcase_35 AC 37 ms
52,096 KB
testcase_36 AC 37 ms
51,840 KB
testcase_37 AC 38 ms
51,840 KB
testcase_38 AC 229 ms
174,416 KB
testcase_39 AC 1,330 ms
190,928 KB
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

def gcd(a: int, b: int) -> int:
    """a, bの最大公約数(greatest common divisor: GCD)を求める
    計算量: O(log(min(a, b)))
    """
    if b == 0:
        return a
    return gcd(b, a%b)


def multi_gcd(array: list) -> int:
    """arrayのGCDを求める"""
    n = len(array)
    ans = array[0]
    for i in range(1, n):
        ans = gcd(ans, array[i])
    return ans


n = int(input())
a = list(map(int, input().split()))

l, r = 0, 0
ans = 0
while True:
    tmp = a[l]
    while True:
        if r == n:
            break
        if gcd(tmp, a[r]) == 1:
            ans += n - r 
            break
        else:
            tmp = gcd(tmp, a[r])
            r += 1
    l += 1
    if l > r:
        r = l
    if l == n:
        break

print(ans)
0