結果
| 問題 |
No.1036 Make One With GCD 2
|
| コンテスト | |
| ユーザー |
convexineq
|
| 提出日時 | 2020-04-26 02:43:32 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 652 bytes |
| コンパイル時間 | 465 ms |
| コンパイル使用メモリ | 82,304 KB |
| 実行使用メモリ | 216,876 KB |
| 最終ジャッジ日時 | 2024-11-08 19:35:08 |
| 合計ジャッジ時間 | 18,307 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 4 |
| other | WA * 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)
print(1)
convexineq