結果

問題 No.1036 Make One With GCD 2
ユーザー chocoruskchocorusk
提出日時 2020-03-14 15:45:09
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 879 ms / 2,000 ms
コード長 547 bytes
コンパイル時間 1,645 ms
コンパイル使用メモリ 86,896 KB
実行使用メモリ 202,004 KB
最終ジャッジ日時 2023-10-14 19:11:13
合計ジャッジ時間 22,205 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 879 ms
198,200 KB
testcase_01 AC 393 ms
161,008 KB
testcase_02 AC 436 ms
169,304 KB
testcase_03 AC 132 ms
106,172 KB
testcase_04 AC 173 ms
120,176 KB
testcase_05 AC 64 ms
71,044 KB
testcase_06 AC 69 ms
70,932 KB
testcase_07 AC 211 ms
110,652 KB
testcase_08 AC 192 ms
101,524 KB
testcase_09 AC 441 ms
182,196 KB
testcase_10 AC 427 ms
172,404 KB
testcase_11 AC 432 ms
151,104 KB
testcase_12 AC 456 ms
172,892 KB
testcase_13 AC 621 ms
189,832 KB
testcase_14 AC 625 ms
198,092 KB
testcase_15 AC 625 ms
184,520 KB
testcase_16 AC 610 ms
186,936 KB
testcase_17 AC 590 ms
187,672 KB
testcase_18 AC 83 ms
76,600 KB
testcase_19 AC 89 ms
77,180 KB
testcase_20 AC 94 ms
77,480 KB
testcase_21 AC 94 ms
77,576 KB
testcase_22 AC 577 ms
184,344 KB
testcase_23 AC 460 ms
154,652 KB
testcase_24 AC 604 ms
187,216 KB
testcase_25 AC 538 ms
172,840 KB
testcase_26 AC 569 ms
182,984 KB
testcase_27 AC 64 ms
71,088 KB
testcase_28 AC 63 ms
71,140 KB
testcase_29 AC 69 ms
71,128 KB
testcase_30 AC 65 ms
70,912 KB
testcase_31 AC 67 ms
71,032 KB
testcase_32 AC 68 ms
70,988 KB
testcase_33 AC 66 ms
71,224 KB
testcase_34 AC 65 ms
70,932 KB
testcase_35 AC 66 ms
71,032 KB
testcase_36 AC 66 ms
70,908 KB
testcase_37 AC 64 ms
71,024 KB
testcase_38 AC 680 ms
201,680 KB
testcase_39 AC 632 ms
201,724 KB
testcase_40 AC 449 ms
154,340 KB
testcase_41 AC 668 ms
201,860 KB
testcase_42 AC 679 ms
201,808 KB
testcase_43 AC 735 ms
202,004 KB
testcase_44 AC 678 ms
201,948 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd
n=int(input())
a=list(map(int, input().split()))
sz=1
while sz<n:
  sz*=2
seg=[0]*(2*sz)
for i in range(n):
  seg[i+sz]=a[i]
for i in range(sz-1, 0, -1):
  seg[i]=gcd(seg[2*i], seg[2*i+1])
def query(a, b):
  if a>=b:
    return 0
  a1=a+sz
  b1=b+sz
  ret=0
  while a1<b1:
    if b1&1:
      b1-=1
      ret=gcd(ret, seg[b1])
    if a1&1:
      ret=gcd(ret, seg[a1])
      a1+=1
    a1>>=1
    b1>>=1
  return ret
ans=0
r=1
for i in range(n):
  while r<=n:
    if query(i, r)==1:
      break
    r+=1
  ans+=(n+1-r)
print(ans)
0