Submission #5148199
Source Code Expand
Copy
def gcd(a,b):return a if b == 0 else gcd(b,a%b)N = int(input())A = [int(x) for x in input().split()]gcd_from_left = [0]*N # 自分のindexは含まないようなものgcd_from_right = [0]*Nfor i in range(1,N):gcd_from_left[i] = gcd(A[i-1],gcd_from_left[i-1])gcd_from_right[N-1-i] = gcd(A[N-i],gcd_from_right[N-i])ans = 0for a,b in zip(gcd_from_left, gcd_from_right):x = gcd(a,b)if ans < x:ans = xprint(ans)
def gcd(a,b): return a if b == 0 else gcd(b,a%b) N = int(input()) A = [int(x) for x in input().split()] gcd_from_left = [0]*N # 自分のindexは含まないようなもの gcd_from_right = [0]*N for i in range(1,N): gcd_from_left[i] = gcd(A[i-1],gcd_from_left[i-1]) gcd_from_right[N-1-i] = gcd(A[N-i],gcd_from_right[N-i]) ans = 0 for a,b in zip(gcd_from_left, gcd_from_right): x = gcd(a,b) if ans < x: ans = x print(ans)
Submission Info
Submission Time | |
---|---|
Task | C - GCD on Blackboard |
User | maspy |
Language | PyPy3 (2.4.0) |
Score | 300 |
Code Size | 465 Byte |
Status | AC |
Exec Time | 279 ms |
Memory | 63984 KB |
Judge Result
Set Name | All | Sample | ||||
---|---|---|---|---|---|---|
Score / Max Score | 300 / 300 | 0 / 0 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
All | sample_01, sample_02, sample_03, 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 |
Sample | sample_01, sample_02, sample_03 |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
sample_01 | AC | 189 ms | 38384 KB |
sample_02 | AC | 192 ms | 38256 KB |
sample_03 | AC | 185 ms | 38256 KB |
testcase_01 | AC | 279 ms | 53068 KB |
testcase_02 | AC | 263 ms | 62704 KB |
testcase_03 | AC | 179 ms | 38256 KB |
testcase_04 | AC | 267 ms | 63984 KB |
testcase_05 | AC | 217 ms | 49392 KB |
testcase_06 | AC | 260 ms | 62704 KB |
testcase_07 | AC | 168 ms | 38384 KB |
testcase_08 | AC | 170 ms | 38256 KB |
testcase_09 | AC | 240 ms | 53640 KB |
testcase_10 | AC | 242 ms | 53724 KB |
testcase_11 | AC | 238 ms | 53400 KB |
testcase_12 | AC | 189 ms | 40560 KB |
testcase_13 | AC | 174 ms | 38256 KB |