結果

問題 No.1036 Make One With GCD 2
ユーザー nehan_der_thalnehan_der_thal
提出日時 2020-04-26 17:15:17
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 617 bytes
コンパイル時間 655 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 223,452 KB
最終ジャッジ日時 2024-04-28 18:56:05
合計ジャッジ時間 18,341 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 285 ms
173,648 KB
testcase_02 AC 384 ms
209,828 KB
testcase_03 AC 99 ms
100,480 KB
testcase_04 AC 125 ms
121,472 KB
testcase_05 AC 41 ms
51,712 KB
testcase_06 AC 42 ms
52,096 KB
testcase_07 WA -
testcase_08 WA -
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 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 42 ms
51,968 KB
testcase_28 AC 41 ms
52,096 KB
testcase_29 AC 41 ms
52,096 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 42 ms
51,840 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 356 ms
223,452 KB
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd
n = int(input())
X = list(map(int, input().split()))
st_f = [(0, 0)]
st_b = [(0, 0)]
r = 0
j = 0
for i in range(n):
    while j<n:
        st_f.append(
                (X[j], gcd(st_f[-1][1], X[j]))
                )
        j += 1
        if gcd(st_f[-1][1], st_b[-1][1]) == 1:
            break
    if j == n and gcd(st_f[-1][1], st_b[-1][1]) != 1:
        j += 1
    if len(st_b) == 1:
        while len(st_f) > 1:
            x, y = st_f.pop()
            st_b.append(
                    (x, gcd(st_b[-1][1], x))
                    )
    st_b.pop()
#    print(i, j)
    r += n+1-j
print(r)
0