結果

問題 No.1036 Make One With GCD 2
ユーザー chineristACchineristAC
提出日時 2020-06-18 02:28:57
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,940 ms / 2,000 ms
コード長 697 bytes
コンパイル時間 509 ms
コンパイル使用メモリ 86,920 KB
実行使用メモリ 234,988 KB
最終ジャッジ日時 2023-09-16 11:57:38
合計ジャッジ時間 42,639 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,640 ms
229,932 KB
testcase_01 AC 1,226 ms
224,436 KB
testcase_02 AC 1,540 ms
234,988 KB
testcase_03 AC 402 ms
117,808 KB
testcase_04 AC 730 ms
151,460 KB
testcase_05 AC 68 ms
71,544 KB
testcase_06 AC 69 ms
71,372 KB
testcase_07 AC 538 ms
123,308 KB
testcase_08 AC 447 ms
116,156 KB
testcase_09 AC 1,293 ms
217,688 KB
testcase_10 AC 1,203 ms
209,584 KB
testcase_11 AC 1,332 ms
223,680 KB
testcase_12 AC 1,202 ms
209,608 KB
testcase_13 AC 1,465 ms
221,668 KB
testcase_14 AC 1,425 ms
222,444 KB
testcase_15 AC 1,316 ms
214,008 KB
testcase_16 AC 1,320 ms
214,220 KB
testcase_17 AC 1,375 ms
221,200 KB
testcase_18 AC 98 ms
77,292 KB
testcase_19 AC 95 ms
77,164 KB
testcase_20 AC 101 ms
78,084 KB
testcase_21 AC 98 ms
78,472 KB
testcase_22 AC 1,307 ms
213,584 KB
testcase_23 AC 948 ms
179,916 KB
testcase_24 AC 1,338 ms
220,540 KB
testcase_25 AC 1,242 ms
205,892 KB
testcase_26 AC 1,272 ms
213,104 KB
testcase_27 AC 70 ms
71,512 KB
testcase_28 AC 70 ms
71,280 KB
testcase_29 AC 68 ms
71,184 KB
testcase_30 AC 69 ms
71,324 KB
testcase_31 AC 85 ms
76,484 KB
testcase_32 AC 88 ms
76,312 KB
testcase_33 AC 70 ms
71,536 KB
testcase_34 AC 80 ms
76,380 KB
testcase_35 AC 68 ms
71,052 KB
testcase_36 AC 69 ms
71,320 KB
testcase_37 AC 70 ms
71,400 KB
testcase_38 AC 1,940 ms
229,684 KB
testcase_39 AC 1,514 ms
229,708 KB
testcase_40 AC 953 ms
179,868 KB
testcase_41 AC 1,554 ms
229,740 KB
testcase_42 AC 1,517 ms
229,904 KB
testcase_43 AC 1,637 ms
229,872 KB
testcase_44 AC 1,655 ms
229,984 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd
import sys

input=sys.stdin.buffer.readline

N=int(input())
A=list(map(int,input().split()))

n=N.bit_length()
_GCD=[[0 for i in range(n)] for i in range(N)]
for i in range(N):
    _GCD[i][0]=A[i]
for j in range(1,n):
    for i in range(N-2**j+1):
        _GCD[i][j]=gcd(_GCD[i][j-1],_GCD[i+2**(j-1)][j-1])

def GCD(l,r):
    b=r-l+1
    m=b.bit_length()-1
    return gcd(_GCD[l][m],_GCD[r-2**m+1][m])

res=0
for i in range(N):
    start=i
    end=N-1
    while end-start>1:
        t=(end+start)//2
        if GCD(i,t)==1:
            end=t
        else:
            start=t
    if GCD(i,start)==1:
        res+=N-start
    elif GCD(i,end)==1:
        res+=N-end

print(res)
0