結果

問題 No.1036 Make One With GCD 2
ユーザー ningenMeningenMe
提出日時 2020-03-14 15:47:18
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 765 bytes
コンパイル時間 204 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 84,532 KB
最終ジャッジ日時 2024-04-24 17:15:24
合計ジャッジ時間 8,165 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10000)
input = sys.stdin.buffer.readline

N = int(input())

def GCD(l,r):
	return l if r == 0 else GCD(r,l % r)

M = 1
while M < N:
	M *= 2
node = [0]*(2*M)

def update(idx,var):
	idx += M
	node[idx] = var
	while idx > 0:
		idx >>= 1
		node[idx] = GCD(node[2*idx + 0],node[2*idx + 1])

def get(l,r):
	vl = 0
	vr = 0
	l += M
	r += M
	while l < r:
		if l&1 :
			vl = GCD(vl,node[l])
			l += 1
		if r&1 :
			r -= 1
			vr = GCD(node[r],vr)
	return GCD(vl,vr)

A = list(map(int,input().split()))
for i in range(N):
	update(i,A[i])

ans = 0
for i in range(N):
	if A[i] == 1:
		ans += (N-i)
	else:
		ok = N
		ng = i
		while ok-ng > 1 :
			md = (ok+ng)//2;
			if get(i,md+1)==1:
				ok = md
			else:
				ng = md
		ans += (N-ok)
print(ans)

0