結果

問題 No.1036 Make One With GCD 2
ユーザー hedwig100hedwig100
提出日時 2020-04-25 21:14:20
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 704 ms / 2,000 ms
コード長 1,012 bytes
コンパイル時間 1,673 ms
コンパイル使用メモリ 86,656 KB
実行使用メモリ 258,796 KB
最終ジャッジ日時 2023-10-14 20:05:05
合計ジャッジ時間 19,755 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 501 ms
256,100 KB
testcase_01 AC 415 ms
223,840 KB
testcase_02 AC 547 ms
225,444 KB
testcase_03 AC 173 ms
127,300 KB
testcase_04 AC 241 ms
160,664 KB
testcase_05 AC 78 ms
71,024 KB
testcase_06 AC 76 ms
71,020 KB
testcase_07 AC 277 ms
135,380 KB
testcase_08 AC 245 ms
121,508 KB
testcase_09 AC 517 ms
246,348 KB
testcase_10 AC 476 ms
231,308 KB
testcase_11 AC 497 ms
215,852 KB
testcase_12 AC 480 ms
232,264 KB
testcase_13 AC 636 ms
243,052 KB
testcase_14 AC 648 ms
253,496 KB
testcase_15 AC 598 ms
222,184 KB
testcase_16 AC 614 ms
237,056 KB
testcase_17 AC 610 ms
226,968 KB
testcase_18 AC 92 ms
76,276 KB
testcase_19 AC 95 ms
76,468 KB
testcase_20 AC 98 ms
76,948 KB
testcase_21 AC 97 ms
76,688 KB
testcase_22 AC 587 ms
221,412 KB
testcase_23 AC 459 ms
179,140 KB
testcase_24 AC 607 ms
224,948 KB
testcase_25 AC 565 ms
209,904 KB
testcase_26 AC 586 ms
220,636 KB
testcase_27 AC 77 ms
70,892 KB
testcase_28 AC 76 ms
71,036 KB
testcase_29 AC 76 ms
71,092 KB
testcase_30 AC 78 ms
71,016 KB
testcase_31 AC 83 ms
75,844 KB
testcase_32 AC 83 ms
75,640 KB
testcase_33 AC 75 ms
71,108 KB
testcase_34 AC 81 ms
75,460 KB
testcase_35 AC 78 ms
71,208 KB
testcase_36 AC 78 ms
71,252 KB
testcase_37 AC 77 ms
71,316 KB
testcase_38 AC 704 ms
258,556 KB
testcase_39 AC 526 ms
258,520 KB
testcase_40 AC 471 ms
179,268 KB
testcase_41 AC 512 ms
258,744 KB
testcase_42 AC 510 ms
258,776 KB
testcase_43 AC 493 ms
258,796 KB
testcase_44 AC 500 ms
258,692 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

INF = 10 ** 9
MOD = 10 **9 + 7
import sys
input = sys.stdin.readline
from math import gcd

class SparseTable():
    def __init__(self,arr,func,unit):
        self.N = len(arr)
        self.K = self.N.bit_length()
        self.func = func
        self.unit = unit
        self.table = [self.unit] * (self.N * self.K)

        for i in range(self.N):
            self.table[i] = arr[i]
        for k in range(1,self.K):
            for i in range(self.N - (1<<(k - 1))):
                self.table[i + k*self.N] = self.func(self.table[i + (k - 1)*self.N],self.table[i + (1<<(k - 1)) + (k - 1)*self.N])
        
    def query(self,l,r):
        if l >= r:
            return self.unit
        k = (r - l).bit_length() - 1
        return self.func(self.table[l + k*self.N],self.table[r - (1<<k) + k*self.N])


n = int(input())
a = list(map(int,input().split()))
sp = SparseTable(a,gcd,0)

r = 0
ans = 0
for l in range(n):
    while r < n and sp.query(l,r + 1) != 1:
        r += 1
    ans += n - r
print(ans)      

0