結果
| 問題 | No.1036 Make One With GCD 2 |
| コンテスト | |
| ユーザー |
ptotq
|
| 提出日時 | 2020-04-25 06:27:09 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 1,900 ms / 2,000 ms |
| コード長 | 644 bytes |
| コンパイル時間 | 237 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 93,136 KB |
| 最終ジャッジ日時 | 2024-09-16 13:37:24 |
| 合計ジャッジ時間 | 39,624 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 41 |
ソースコード
from math import gcd
import sys
readline = sys.stdin.readline
def push(a, x):
a.append((x, gcd(x, a[-1][1])))
def pop(front, back):
if len(back) == 1:
for _ in range(len(front)-1):
back.append(gcd(front.pop()[0], back[-1]))
back.pop()
def fold(front, back):
return gcd(front[-1][1], back[-1])
N = int(input())
a = list(map(int, input().split()))
r = 0
ans = 0
front, back = [(0, 0)], [0]
for l in range(N):
while r < N and gcd(fold(front, back), a[r]) != 1:
push(front, a[r])
r += 1
ans += N - r
if l < r:
pop(front, back)
else:
r += 1
print(ans)
ptotq