class SegmentTree: def __init__(self, op, e, v): self.e = e self.op = op self.n = len(v) self.N = 2 ** (self.n-1).bit_length() self.seg_data = [e for _ in range(self.N-1)] \ + v + [e for _ in range(self.N-self.n)] for i in range(2*self.N-2, 0, -2): self.seg_data[(i-1)//2] = op(self.seg_data[i], self.seg_data[i-1]) def __len__(self): return self.n def __getitem__(self, i): return self.seg_data[self.N-1+i] def __setitem__(self, i, x): idx = self.N - 1 + i self.seg_data[idx] = x while idx: idx = (idx-1) // 2 self.seg_data[idx] = self.op(self.seg_data[2*idx+1], self.seg_data[2*idx+2]) def query(self, i, j): # [i, j) if i == j: return None else: idx1 = self.N - 1 + i idx2 = self.N - 2 + j # 閉区間にする result = self.e while idx1 < idx2 + 1: if idx1&1 == 0: # idx1が偶数 result = self.op(result, self.seg_data[idx1]) if idx2&1 == 1: # idx2が奇数 result = self.op(result, self.seg_data[idx2]) idx2 -= 1 idx1 //= 2 idx2 = (idx2 - 1)//2 return result def find_left(self, i): if self.query(0, i+1) != 1: return -1 if self.seg_data[self.N-1+i] == 1: return i left = 0; right = i while left + 1 < right: mid = (left + right) // 2 if self.query(mid, i+1) != 1: right = mid else: left = mid return left from math import gcd N = int(input()) A = list(map(int, input().split())) def op(x, y): if x is None: return y if y is None: return x return gcd(x, y) seg = SegmentTree(op=op, e=None, v=A) ans = N * (N+1) // 2 for i in range(N): left = seg.find_left(i) ans -= i - left print(ans)