結果

問題 No.1036 Make One With GCD 2
ユーザー nehan_der_thalnehan_der_thal
提出日時 2020-04-26 17:19:09
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 608 ms / 2,000 ms
コード長 633 bytes
コンパイル時間 748 ms
コンパイル使用メモリ 86,736 KB
実行使用メモリ 218,216 KB
最終ジャッジ日時 2023-10-14 20:21:28
合計ジャッジ時間 17,428 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 296 ms
192,796 KB
testcase_01 AC 284 ms
152,272 KB
testcase_02 AC 327 ms
214,256 KB
testcase_03 AC 113 ms
101,464 KB
testcase_04 AC 143 ms
112,280 KB
testcase_05 AC 67 ms
71,096 KB
testcase_06 AC 68 ms
71,012 KB
testcase_07 AC 208 ms
105,796 KB
testcase_08 AC 189 ms
99,512 KB
testcase_09 AC 423 ms
173,968 KB
testcase_10 AC 407 ms
164,156 KB
testcase_11 AC 407 ms
142,184 KB
testcase_12 AC 392 ms
164,400 KB
testcase_13 AC 597 ms
181,320 KB
testcase_14 AC 608 ms
189,712 KB
testcase_15 AC 595 ms
176,256 KB
testcase_16 AC 577 ms
177,988 KB
testcase_17 AC 601 ms
179,224 KB
testcase_18 AC 88 ms
76,412 KB
testcase_19 AC 89 ms
76,516 KB
testcase_20 AC 89 ms
76,456 KB
testcase_21 AC 89 ms
76,444 KB
testcase_22 AC 578 ms
175,948 KB
testcase_23 AC 441 ms
139,404 KB
testcase_24 AC 581 ms
178,544 KB
testcase_25 AC 541 ms
164,268 KB
testcase_26 AC 570 ms
174,392 KB
testcase_27 AC 71 ms
70,956 KB
testcase_28 AC 71 ms
70,916 KB
testcase_29 AC 70 ms
70,936 KB
testcase_30 AC 70 ms
71,176 KB
testcase_31 AC 69 ms
71,176 KB
testcase_32 AC 70 ms
71,320 KB
testcase_33 AC 69 ms
71,248 KB
testcase_34 AC 69 ms
71,264 KB
testcase_35 AC 67 ms
71,168 KB
testcase_36 AC 66 ms
71,020 KB
testcase_37 AC 66 ms
71,288 KB
testcase_38 AC 306 ms
218,216 KB
testcase_39 AC 295 ms
193,824 KB
testcase_40 AC 445 ms
155,348 KB
testcase_41 AC 318 ms
194,136 KB
testcase_42 AC 315 ms
193,764 KB
testcase_43 AC 325 ms
195,752 KB
testcase_44 AC 328 ms
195,616 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd
n = int(input())
X = list(map(int, input().split()))
st_f = [(0, 0), (X[0], X[0])]
st_b = [(0, 0)]
r = 0
j = 0
for i in range(n):
    while j<n-1:
        if gcd(st_f[-1][1], st_b[-1][1]) == 1:
            break
        j += 1
        st_f.append(
                (X[j], gcd(st_f[-1][1], X[j]))
                )
    if j == n-1 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-j
print(r)
0