結果

問題 No.1036 Make One With GCD 2
ユーザー Kiri8128Kiri8128
提出日時 2020-04-24 23:11:05
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,761 ms / 2,000 ms
コード長 538 bytes
コンパイル時間 626 ms
コンパイル使用メモリ 86,384 KB
実行使用メモリ 235,508 KB
最終ジャッジ日時 2023-10-14 19:34:38
合計ジャッジ時間 35,566 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 973 ms
232,460 KB
testcase_01 AC 919 ms
196,836 KB
testcase_02 AC 945 ms
215,240 KB
testcase_03 AC 347 ms
116,420 KB
testcase_04 AC 542 ms
150,688 KB
testcase_05 AC 68 ms
70,888 KB
testcase_06 AC 69 ms
70,892 KB
testcase_07 AC 432 ms
122,564 KB
testcase_08 AC 355 ms
118,624 KB
testcase_09 AC 1,045 ms
213,848 KB
testcase_10 AC 977 ms
202,620 KB
testcase_11 AC 1,085 ms
215,804 KB
testcase_12 AC 995 ms
203,732 KB
testcase_13 AC 1,208 ms
223,192 KB
testcase_14 AC 1,223 ms
229,212 KB
testcase_15 AC 1,156 ms
214,436 KB
testcase_16 AC 1,189 ms
216,692 KB
testcase_17 AC 1,218 ms
220,312 KB
testcase_18 AC 95 ms
77,356 KB
testcase_19 AC 95 ms
77,100 KB
testcase_20 AC 99 ms
77,368 KB
testcase_21 AC 97 ms
77,352 KB
testcase_22 AC 1,156 ms
213,464 KB
testcase_23 AC 883 ms
168,420 KB
testcase_24 AC 1,212 ms
218,912 KB
testcase_25 AC 1,091 ms
201,488 KB
testcase_26 AC 1,175 ms
210,940 KB
testcase_27 AC 68 ms
71,132 KB
testcase_28 AC 66 ms
70,928 KB
testcase_29 AC 67 ms
70,912 KB
testcase_30 AC 67 ms
71,188 KB
testcase_31 AC 75 ms
75,908 KB
testcase_32 AC 76 ms
75,828 KB
testcase_33 AC 67 ms
70,996 KB
testcase_34 AC 74 ms
75,776 KB
testcase_35 AC 69 ms
71,188 KB
testcase_36 AC 69 ms
70,912 KB
testcase_37 AC 69 ms
70,996 KB
testcase_38 AC 880 ms
235,140 KB
testcase_39 AC 950 ms
235,112 KB
testcase_40 AC 832 ms
168,616 KB
testcase_41 AC 1,736 ms
235,508 KB
testcase_42 AC 1,761 ms
235,188 KB
testcase_43 AC 1,528 ms
235,204 KB
testcase_44 AC 1,637 ms
235,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def gcd(a, b):
    while b: a, b = b, a % b
    return a

N = int(input())
A = [int(a) for a in input().split()]
nn = (N - 1).bit_length()
X = [A] + [[0] * N for _ in range(nn)]

for i in range(nn):
    for j in range(N - (1 << i + 1) + 1):
        X[i+1][j] = gcd(X[i][j], X[i][j + (1 << i)])

def calc(i, j):
    if i == j: return 0
    a = (i - j).bit_length() - 1
    return gcd(X[a][j], X[a][i-(1<<a)])

j = 0
ans = 0
for i in range(1, N + 1):
    while calc(i, j) == 1:
        j += 1
    ans += i - j

print(N * (N + 1) // 2 - ans)
0