๋ฌธ์
๋ฌธ์ ์ค๋ช
- ์ฒ ์๊ฐ ๊ฐ์ง ์นด๋๋ค์ ์ ํ ๋ชจ๋ ์ซ์๋ฅผ ๋๋ ์ ์๊ณ ์ํฌ๊ฐ ๊ฐ์ง ์นด๋๋ค์ ์ ํ ๋ชจ๋ ์ซ์๋ค ์ค ํ๋๋ ๋๋ ์ ์๋ ์์ ์ ์ a
- ์ํฌ๊ฐ ๊ฐ์ง ์นด๋๋ค์ ์ ํ ๋ชจ๋ ์ซ์๋ฅผ ๋๋ ์ ์๊ณ , ์ฒ ์๊ฐ ๊ฐ์ง ์นด๋๋ค์ ์ ํ ๋ชจ๋ ์ซ์๋ค ์ค ํ๋๋ ๋๋ ์ ์๋ ์์ ์ ์ a
์๋ฅผ ๋ค์ด, ์นด๋๋ค์ 10, 5, 20, 17์ด ์ ํ ์๋ ๊ฒฝ์ฐ์ ๋ํด ์๊ฐํด ๋ด ์๋ค. ๋ง์ฝ, ์ฒ ์๊ฐ [10, 17]์ด ์ ํ ์นด๋๋ฅผ ๊ฐ๊ณ , ์ํฌ๊ฐ [5, 20]์ด ์ ํ ์นด๋๋ฅผ ๊ฐ๋๋ค๋ฉด ๋ ์กฐ๊ฑด ์ค ํ๋๋ฅผ ๋ง์กฑํ๋ ์์ ์ ์ a๋ ์กด์ฌํ์ง ์์ต๋๋ค. ํ์ง๋ง, ์ฒ ์๊ฐ [10, 20]์ด ์ ํ ์นด๋๋ฅผ ๊ฐ๊ณ , ์ํฌ๊ฐ [5, 17]์ด ์ ํ ์นด๋๋ฅผ ๊ฐ๋๋ค๋ฉด, ์ฒ ์๊ฐ ๊ฐ์ง ์นด๋๋ค์ ์ซ์๋ ๋ชจ๋ 10์ผ๋ก ๋๋ ์ ์๊ณ , ์ํฌ๊ฐ ๊ฐ์ง ์นด๋๋ค์ ์ซ์๋ ๋ชจ๋ 10์ผ๋ก ๋๋ ์ ์์ต๋๋ค. ๋ฐ๋ผ์ ์ฒ ์์ ์ํฌ๋ ๊ฐ๊ฐ [10, 20]์ด ์ ํ ์นด๋, [5, 17]์ด ์ ํ ์นด๋๋ก ๋๋ ๊ฐ์ก๋ค๋ฉด ์กฐ๊ฑด์ ํด๋นํ๋ ์์ ์ ์ a๋ 10์ด ๋ฉ๋๋ค.
์ฒ ์๊ฐ ๊ฐ์ง ์นด๋์ ์ ํ ์ซ์๋ค์ ๋ํ๋ด๋ ์ ์ ๋ฐฐ์ด arrayA์ ์ํฌ๊ฐ ๊ฐ์ง ์นด๋์ ์ ํ ์ซ์๋ค์ ๋ํ๋ด๋ ์ ์ ๋ฐฐ์ด arrayB๊ฐ ์ฃผ์ด์ก์ ๋, ์ฃผ์ด์ง ์กฐ๊ฑด์ ๋ง์กฑํ๋ ๊ฐ์ฅ ํฐ ์์ ์ ์ a๋ฅผ returnํ๋๋ก solution ํจ์๋ฅผ ์์ฑํด ์ฃผ์ธ์. ๋ง์ฝ, ์กฐ๊ฑด์ ๋ง์กฑํ๋ a๊ฐ ์๋ค๋ฉด, 0์ return ํด ์ฃผ์ธ์.
์ ํ์ฌํญ
- 1 ≤ arrayA์ ๊ธธ์ด = arrayB์ ๊ธธ์ด ≤ 500,000
- 1 ≤ arrayA์ ์์, arrayB์ ์์ ≤ 100,000,000
- arrayA์ arrayB์๋ ์ค๋ณต๋ ์์๊ฐ ์์ ์ ์์ต๋๋ค.
์ ์ถ๋ ฅ ์
arrayA | arrayB | result |
[10, 17] | [5, 20] | 0 |
[10, 20] | [5, 17] | 10 |
[14, 35, 119] | [18, 30, 102] | 7 |
์ ์ถ๋ ฅ ์ ์ค๋ช
์ ์ถ๋ ฅ ์ #1
- ๋ฌธ์ ์์์ ๊ฐ์ต๋๋ค.
์ ์ถ๋ ฅ ์ #2
- ๋ฌธ์ ์์์ ๊ฐ์ต๋๋ค.
์ ์ถ๋ ฅ ์ #3
- ์ฒ ์๊ฐ ๊ฐ์ง ์นด๋์ ์ ํ ์ซ์๋ค์ ๋ชจ๋ 3์ผ๋ก ๋๋ ์ ์๊ณ , ์ํฌ๊ฐ ๊ฐ์ง ์นด๋์ ์ ํ ์ซ์๋ ๋ชจ๋ 3์ผ๋ก ๋๋ ์ ์์ต๋๋ค. ๋ฐ๋ผ์ 3์ ์กฐ๊ฑด์ ํด๋นํ๋ ์์ ์ ์์ ๋๋ค. ํ์ง๋ง, ์ฒ ์๊ฐ ๊ฐ์ง ์นด๋๋ค์ ์ ํ ์ซ์๋ค์ ๋ชจ๋ 7๋ก ๋๋ ์ ์๊ณ , ์ํฌ๊ฐ ๊ฐ์ง ์นด๋๋ค์ ์ ํ ์ซ์๋ ๋ชจ๋ 7๋ก ๋๋ ์ ์์ต๋๋ค. ๋ฐ๋ผ์ ์ต๋๊ฐ์ธ 7์ return ํฉ๋๋ค.
๋ฌธ์ ํ์ด
- ๋ฌด์ง์ฑ ์ฝ๋ฉ
def solution(arrayA, arrayB):
arrayA = list(set(arrayA))
arrayB = list(set(arrayB))
arrayA.sort()
arrayB.sort()
arrayAlen = len(arrayA)
arrayBlen = len(arrayB)
divisorsA = set()
divisorsB = set()
n = max(arrayA[0]+1, int(arrayA[-1]**0.5)+1)
for i in range(2, n):
is_break = False
for j in arrayA:
if j % i != 0:
is_break = True
break
if is_break == False:
divisorsA.add(i)
n = max(arrayB[0]+1, int(arrayB[-1]**0.5)+1)
for i in range(2, n):
is_break = False
for j in arrayB:
if j % i != 0:
is_break = True
break
if is_break == False:
divisorsB.add(i)
divisorsA = list(divisorsA)
divisorsB = list(divisorsB)
divisorsA.sort(reverse=True)
divisorsB.sort(reverse=True)
print(divisorsA, divisorsB)
if len(divisorsA) == 0 and len(divisorsB) == 0:
return 0
elif len(divisorsA) == 0:
# divisorsB์ ์๋ ๊ฑธ๋ก arrayA ๋๋ ๋ณด๊ธฐ
for i in divisorsB:
is_break = False
for j in arrayA:
print(j,i)
if j % i == 0:
is_break = True
break
if is_break == False:
return i
return 0
elif len(divisorsB) == 0:
# divisorsA์ ์๋ ๊ฑธ๋ก arrayB ๋๋ ๋ณด๊ธฐ
for i in divisorsA:
is_break = False
for j in arrayB:
print(j,i)
if j % i == 0:
is_break = True
break
if is_break == False:
return i
else:
A_used = True
B_used = True
a = 0
b = 0
_t = 0
while len(divisorsA) > 0 or len(divisorsB) > 0:
if len(divisorsA) != 0 and A_used == True:
A_used = False
a = divisorsA.pop(0)
if len(divisorsB) != 0 and B_used == True:
B_used = False
b = divisorsB.pop(0)
if a == b:
A_used = True
B_used = True
b = 0
a = 0
elif a > b:
A_used = True
is_break = False
for j in arrayB:
if j % a == 0:
is_break = True
break
if is_break == False:
return a
a = 0
else:
B_used = True
is_break = False
for j in arrayA:
if j % b == 0:
is_break = True
break
if is_break == False:
return b
b = 0
return 0
return 0
- ๋น์ฐํ์ง๋ง ์ฝ๋๊ฐ ๊ธธ๋ฉด ํ์ด์ฌ์ ์๊ฐ ์ด๊ณผ๋จ
์ ํ์ฑ ํ
์คํธ
ํ
์คํธ 1 ใ ํต๊ณผ (250.26ms, 10.3MB)
ํ
์คํธ 2 ใ ํต๊ณผ (222.42ms, 10.4MB)
ํ
์คํธ 3 ใ ํต๊ณผ (284.40ms, 10.4MB)
ํ
์คํธ 4 ใ ํต๊ณผ (210.04ms, 13.3MB)
ํ
์คํธ 5 ใ ํต๊ณผ (203.27ms, 11.3MB)
ํ
์คํธ 6 ใ ํต๊ณผ (205.46ms, 11.8MB)
ํ
์คํธ 7 ใ ํต๊ณผ (203.34ms, 10.4MB)
ํ
์คํธ 8 ใ ํต๊ณผ (212.16ms, 10.4MB)
ํ
์คํธ 9 ใ ํต๊ณผ (297.72ms, 11.2MB)
ํ
์คํธ 10 ใ ํต๊ณผ (217.82ms, 10.5MB)
ํ
์คํธ 11 ใ ์คํจ (์๊ฐ ์ด๊ณผ)
ํ
์คํธ 12 ใ ์คํจ (์๊ฐ ์ด๊ณผ)
ํ
์คํธ 13 ใ ์คํจ (์๊ฐ ์ด๊ณผ)
ํ
์คํธ 14 ใ ์คํจ (์๊ฐ ์ด๊ณผ)
ํ
์คํธ 15 ใ ์คํจ (์๊ฐ ์ด๊ณผ)
ํ
์คํธ 16 ใ ์คํจ (์๊ฐ ์ด๊ณผ)
ํ
์คํธ 17 ใ ์คํจ (์๊ฐ ์ด๊ณผ)
ํ
์คํธ 18 ใ ์คํจ (์๊ฐ ์ด๊ณผ)
ํ
์คํธ 19 ใ ํต๊ณผ (0.01ms, 10.3MB)
ํ
์คํธ 20 ใ ํต๊ณผ (0.03ms, 10.4MB)
ํ
์คํธ 21 ใ ํต๊ณผ (0.03ms, 10.2MB)
ํ
์คํธ 22 ใ ํต๊ณผ (0.03ms, 10.3MB)
ํ
์คํธ 23 ใ ํต๊ณผ (4.82ms, 10.2MB)
ํ
์คํธ 24 ใ ํต๊ณผ (323.12ms, 10.3MB)
ํ
์คํธ 25 ใ ํต๊ณผ (9741.68ms, 10.3MB)
ํ
์คํธ 26 ใ ํต๊ณผ (5803.71ms, 10.5MB)
ํ
์คํธ 27 ใ ํต๊ณผ (0.35ms, 10.3MB)
ํ
์คํธ 28 ใ ํต๊ณผ (0.58ms, 10.5MB)
ํ
์คํธ 29 ใ ํต๊ณผ (0.60ms, 10.3MB)
ํ
์คํธ 30 ใ ํต๊ณผ (0.65ms, 10.3MB)
ํ
์คํธ 31 ใ ํต๊ณผ (0.91ms, 10.5MB)
ํ
์คํธ 32 ใ ํต๊ณผ (1.17ms, 10.4MB)
ํ
์คํธ 33 ใ ํต๊ณผ (177.98ms, 10.3MB)
ํ
์คํธ 34 ใ ํต๊ณผ (0.15ms, 10.3MB)
ํ
์คํธ 35 ใ ํต๊ณผ (0.09ms, 10.4MB)
ํ
์คํธ 36 ใ ํต๊ณผ (0.15ms, 10.4MB)
- ๋์ ๋จธ๋ฆฌ๊ฐ ๋ฉ์ฒญ์ด์๋ค. ํด๋จผ.
- ๋ฌธ์ ์์ฒด๊ฐ ํจ์ ์ด์๋ค. ํด๋จผ.
- ๋ฆฌ์คํธ์์ ์ต๋ ๊ณต์ฝ ์๋ฅผ ๊ตฌํ๊ณ , ๊ทธ๊ฑธ๋ก ์๋ ๋ฆฌ์คํธ๋ฅผ ๋๋ ์ 0์ด ๋์ค๋ฉด ๋ ๋ณผ ํ์๊ฐ ์์ด ๋๋๊ฑฐ๋ค.
- ์์ ์ง ์์ค๋ ๋ชจ๋ ์ฝ์๋ฅผ ๋ค ๊ณ์ฐํ๊ณ ์์๊ธฐ ๋๋ฌธ์ ์๊ฐ ์ด๊ณผ๊ฐ ๋ฌ๋ ๊ฒ...
import math
def solution(arrayA, arrayB):
arrayA = list(set(arrayA))
len_arrayA = len(arrayA)
gcdA = arrayA[0]
if len_arrayA != 1:
for i in range(1,len_arrayA):
gcdA = math.gcd(gcdA, arrayA[i])
arrayB = list(set(arrayB))
len_arrayB = len(arrayB)
gcdB = arrayB[0]
if len_arrayB != 1:
for i in range(1,len_arrayB):
gcdB = math.gcd(gcdB, arrayB[i])
for i in arrayA:
if i % gcdB == 0:
gcdB = 1
break
for i in arrayB:
if i % gcdA == 0:
gcdA = 1
break
if gcdA == 1:
if gcdB == 1:
return 0
else:
return gcdB
else:
if gcdB == 1:
return gcdA
else:
return max(gcdA, gcdB)
์ ํ์ฑ ํ
์คํธ
ํ
์คํธ 1 ใ ํต๊ณผ (0.29ms, 10.3MB)
ํ
์คํธ 2 ใ ํต๊ณผ (1.18ms, 10.5MB)
ํ
์คํธ 3 ใ ํต๊ณผ (0.16ms, 10.2MB)
ํ
์คํธ 4 ใ ํต๊ณผ (7.02ms, 13.4MB)
ํ
์คํธ 5 ใ ํต๊ณผ (2.84ms, 11MB)
ํ
์คํธ 6 ใ ํต๊ณผ (4.73ms, 11.7MB)
ํ
์คํธ 7 ใ ํต๊ณผ (0.69ms, 10.6MB)
ํ
์คํธ 8 ใ ํต๊ณผ (0.38ms, 10.5MB)
ํ
์คํธ 9 ใ ํต๊ณผ (2.87ms, 11.2MB)
ํ
์คํธ 10 ใ ํต๊ณผ (0.16ms, 10.2MB)
ํ
์คํธ 11 ใ ํต๊ณผ (228.88ms, 82.9MB)
ํ
์คํธ 12 ใ ํต๊ณผ (271.21ms, 82.8MB)
ํ
์คํธ 13 ใ ํต๊ณผ (225.80ms, 82.8MB)
ํ
์คํธ 14 ใ ํต๊ณผ (216.91ms, 82.8MB)
ํ
์คํธ 15 ใ ํต๊ณผ (220.48ms, 82.8MB)
ํ
์คํธ 16 ใ ํต๊ณผ (215.80ms, 82.9MB)
ํ
์คํธ 17 ใ ํต๊ณผ (189.72ms, 83MB)
ํ
์คํธ 18 ใ ํต๊ณผ (222.93ms, 82.9MB)
ํ
์คํธ 19 ใ ํต๊ณผ (0.00ms, 10.2MB)
ํ
์คํธ 20 ใ ํต๊ณผ (0.01ms, 10.4MB)
ํ
์คํธ 21 ใ ํต๊ณผ (0.01ms, 10.2MB)
ํ
์คํธ 22 ใ ํต๊ณผ (0.01ms, 10MB)
ํ
์คํธ 23 ใ ํต๊ณผ (0.01ms, 10.2MB)
ํ
์คํธ 24 ใ ํต๊ณผ (0.01ms, 10.4MB)
ํ
์คํธ 25 ใ ํต๊ณผ (0.01ms, 10MB)
ํ
์คํธ 26 ใ ํต๊ณผ (0.01ms, 10.2MB)
ํ
์คํธ 27 ใ ํต๊ณผ (0.07ms, 10.4MB)
ํ
์คํธ 28 ใ ํต๊ณผ (0.05ms, 10.1MB)
ํ
์คํธ 29 ใ ํต๊ณผ (0.01ms, 10.4MB)
ํ
์คํธ 30 ใ ํต๊ณผ (0.01ms, 10.2MB)
ํ
์คํธ 31 ใ ํต๊ณผ (0.01ms, 10.2MB)
ํ
์คํธ 32 ใ ํต๊ณผ (0.01ms, 10.1MB)
ํ
์คํธ 33 ใ ํต๊ณผ (0.01ms, 10.2MB)
ํ
์คํธ 34 ใ ํต๊ณผ (0.01ms, 10.2MB)
ํ
์คํธ 35 ใ ํต๊ณผ (0.01ms, 10.2MB)
ํ
์คํธ 36 ใ ํต๊ณผ (0.01ms, 10.2MB)
- ๊ทธ๋ฆฌ๊ณ ๋ฐฐ์ด ๊ธธ์ด๋ ๊ฐ๋ค?
- ์ฝ๋ ๋ ์ค์ผ ์ ์๋ค.
import math
from functools import reduce
def solution(arrayA, arrayB):
len_arrayA = len(arrayA)
gcdA = arrayA[0]
gcdB = arrayB[0]
for i in range(1,len_arrayA):
gcdA = math.gcd(gcdA, arrayA[i])
gcdB = math.gcd(gcdB, arrayB[i])
for i in arrayA:
if i % gcdB == 0:
gcdB = 1
break
for i in arrayB:
if i % gcdA == 0:
gcdA = 1
break
if gcdA == 1:
if gcdB == 1:
return 0
else:
return gcdB
else:
if gcdB == 1:
return gcdA
else:
return max(gcdA, gcdB)
์ ํ์ฑ ํ
์คํธ
ํ
์คํธ 1 ใ ํต๊ณผ (0.21ms, 10.3MB)
ํ
์คํธ 2 ใ ํต๊ณผ (0.87ms, 10.2MB)
ํ
์คํธ 3 ใ ํต๊ณผ (0.14ms, 10.2MB)
ํ
์คํธ 4 ใ ํต๊ณผ (10.44ms, 12.9MB)
ํ
์คํธ 5 ใ ํต๊ณผ (3.44ms, 10.4MB)
ํ
์คํธ 6 ใ ํต๊ณผ (4.58ms, 11.1MB)
ํ
์คํธ 7 ใ ํต๊ณผ (0.39ms, 10.3MB)
ํ
์คํธ 8 ใ ํต๊ณผ (0.56ms, 10.2MB)
ํ
์คํธ 9 ใ ํต๊ณผ (1.84ms, 10.6MB)
ํ
์คํธ 10 ใ ํต๊ณผ (0.21ms, 10.2MB)
ํ
์คํธ 11 ใ ํต๊ณผ (143.83ms, 53.3MB)
ํ
์คํธ 12 ใ ํต๊ณผ (174.65ms, 53.2MB)
ํ
์คํธ 13 ใ ํต๊ณผ (183.44ms, 53.2MB)
ํ
์คํธ 14 ใ ํต๊ณผ (217.14ms, 53.2MB)
ํ
์คํธ 15 ใ ํต๊ณผ (150.58ms, 53.2MB)
ํ
์คํธ 16 ใ ํต๊ณผ (144.12ms, 53.2MB)
ํ
์คํธ 17 ใ ํต๊ณผ (212.05ms, 53.1MB)
ํ
์คํธ 18 ใ ํต๊ณผ (139.89ms, 53.5MB)
ํ
์คํธ 19 ใ ํต๊ณผ (0.00ms, 10.2MB)
ํ
์คํธ 20 ใ ํต๊ณผ (0.01ms, 10.1MB)
ํ
์คํธ 21 ใ ํต๊ณผ (0.01ms, 10.1MB)
ํ
์คํธ 22 ใ ํต๊ณผ (0.01ms, 10.2MB)
ํ
์คํธ 23 ใ ํต๊ณผ (0.01ms, 10MB)
ํ
์คํธ 24 ใ ํต๊ณผ (0.01ms, 10.2MB)
ํ
์คํธ 25 ใ ํต๊ณผ (0.01ms, 10.1MB)
ํ
์คํธ 26 ใ ํต๊ณผ (0.01ms, 10.2MB)
ํ
์คํธ 27 ใ ํต๊ณผ (0.03ms, 10MB)
ํ
์คํธ 28 ใ ํต๊ณผ (0.04ms, 10.2MB)
ํ
์คํธ 29 ใ ํต๊ณผ (0.00ms, 10.2MB)
ํ
์คํธ 30 ใ ํต๊ณผ (0.00ms, 10MB)
ํ
์คํธ 31 ใ ํต๊ณผ (0.01ms, 10.1MB)
ํ
์คํธ 32 ใ ํต๊ณผ (0.00ms, 10.2MB)
ํ
์คํธ 33 ใ ํต๊ณผ (0.01ms, 10.4MB)
ํ
์คํธ 34 ใ ํต๊ณผ (0.01ms, 9.97MB)
ํ
์คํธ 35 ใ ํต๊ณผ (0.01ms, 10.1MB)
ํ
์คํธ 36 ใ ํต๊ณผ (0.01ms, 10.2MB)
- ์ฝ๋ ์ค์ด๊ธฐ
import math
from functools import reduce
def solution(arrayA, arrayB):
len_arrayA = len(arrayA)
gcdA = arrayA[0]
gcdB = arrayB[0]
for i in range(1,len_arrayA):
gcdA = math.gcd(gcdA, arrayA[i])
gcdB = math.gcd(gcdB, arrayB[i])
for i in reversed(arrayA):
if i % gcdB == 0:
gcdB = 1
break
for i in reversed(arrayB):
if i % gcdA == 0:
gcdA = 1
break
if gcdA == gcdB:
return 0
else:
return max(gcdA, gcdB)
์ ํ์ฑ ํ
์คํธ
ํ
์คํธ 1 ใ ํต๊ณผ (0.37ms, 10.2MB)
ํ
์คํธ 2 ใ ํต๊ณผ (1.54ms, 10.1MB)
ํ
์คํธ 3 ใ ํต๊ณผ (0.08ms, 10.2MB)
ํ
์คํธ 4 ใ ํต๊ณผ (10.02ms, 12.8MB)
ํ
์คํธ 5 ใ ํต๊ณผ (2.36ms, 10.2MB)
ํ
์คํธ 6 ใ ํต๊ณผ (5.05ms, 11MB)
ํ
์คํธ 7 ใ ํต๊ณผ (0.35ms, 10.1MB)
ํ
์คํธ 8 ใ ํต๊ณผ (0.32ms, 10.2MB)
ํ
์คํธ 9 ใ ํต๊ณผ (3.44ms, 10.5MB)
ํ
์คํธ 10 ใ ํต๊ณผ (0.11ms, 10.1MB)
ํ
์คํธ 11 ใ ํต๊ณผ (147.29ms, 53.2MB)
ํ
์คํธ 12 ใ ํต๊ณผ (148.26ms, 53.4MB)
ํ
์คํธ 13 ใ ํต๊ณผ (159.85ms, 53.3MB)
ํ
์คํธ 14 ใ ํต๊ณผ (174.96ms, 53.4MB)
ํ
์คํธ 15 ใ ํต๊ณผ (169.69ms, 53.2MB)
ํ
์คํธ 16 ใ ํต๊ณผ (171.18ms, 53.2MB)
ํ
์คํธ 17 ใ ํต๊ณผ (136.89ms, 53.4MB)
ํ
์คํธ 18 ใ ํต๊ณผ (168.21ms, 53.3MB)
ํ
์คํธ 19 ใ ํต๊ณผ (0.00ms, 10.1MB)
ํ
์คํธ 20 ใ ํต๊ณผ (0.01ms, 10.1MB)
ํ
์คํธ 21 ใ ํต๊ณผ (0.01ms, 10.1MB)
ํ
์คํธ 22 ใ ํต๊ณผ (0.03ms, 10.1MB)
ํ
์คํธ 23 ใ ํต๊ณผ (0.02ms, 10.2MB)
ํ
์คํธ 24 ใ ํต๊ณผ (0.01ms, 10.1MB)
ํ
์คํธ 25 ใ ํต๊ณผ (0.01ms, 10.1MB)
ํ
์คํธ 26 ใ ํต๊ณผ (0.01ms, 10MB)
ํ
์คํธ 27 ใ ํต๊ณผ (0.06ms, 10MB)
ํ
์คํธ 28 ใ ํต๊ณผ (0.05ms, 10.1MB)
ํ
์คํธ 29 ใ ํต๊ณผ (0.01ms, 10.1MB)
ํ
์คํธ 30 ใ ํต๊ณผ (0.01ms, 10.1MB)
ํ
์คํธ 31 ใ ํต๊ณผ (0.00ms, 10.2MB)
ํ
์คํธ 32 ใ ํต๊ณผ (0.01ms, 10.1MB)
ํ
์คํธ 33 ใ ํต๊ณผ (0.01ms, 10.1MB)
ํ
์คํธ 34 ใ ํต๊ณผ (0.01ms, 10.2MB)
ํ
์คํธ 35 ใ ํต๊ณผ (0.01ms, 10.1MB)
ํ
์คํธ 36 ใ ํต๊ณผ (0.01ms, 10MB)
๋ค ํ๊ณ ๋๋ฉด ์ฌ์ด๋ฐ, ํ๊ธฐ์ ๊น์ง๋ ์ฐธ ์ด๋ ต๋ค... 400์ ๋ฒฝ์ ๋ซ๊ธฐ๊ฐ ์ด๋ ๊ฒ ํ๋๋?
์์ฐธ ๊ณ ์์ ํ์ด ๋ฆฌ๋์ค๋ฅผ ์ด๋ ๊ฒ ์ฐ๋ ๊ฑฐ์๊ตฌ๋. reduce ์จ๋ณด๋ ค๋ค๊ฐ ๊ณต๋ถ๊ฐ ๋๋์ ํฌ๊ธฐํ๋๋ฐ ใ ใ ใ
from math import gcd
from functools import reduce
def check(arrayA, arrayB):
gcd_A = reduce(gcd, arrayA, arrayA[0])
factors = [i for i in range(1, gcd_A//2+1) if not gcd_A % i]
factors.append(gcd_A)
for factor in factors[::-1]:
if all(i % factor for i in arrayB):
return gcd_A
return 0
def solution(arrayA, arrayB):
return max(check(arrayA, arrayB), check(arrayB, arrayA))
์ ํ์ฑ ํ
์คํธ
ํ
์คํธ 1 ใ ํต๊ณผ (0.42ms, 10.3MB)
ํ
์คํธ 2 ใ ํต๊ณผ (0.76ms, 10.3MB)
ํ
์คํธ 3 ใ ํต๊ณผ (0.59ms, 10.2MB)
ํ
์คํธ 4 ใ ํต๊ณผ (8.17ms, 12.9MB)
ํ
์คํธ 5 ใ ํต๊ณผ (2.45ms, 10.5MB)
ํ
์คํธ 6 ใ ํต๊ณผ (5.01ms, 11.2MB)
ํ
์คํธ 7 ใ ํต๊ณผ (0.50ms, 10.3MB)
ํ
์คํธ 8 ใ ํต๊ณผ (1.00ms, 10.3MB)
ํ
์คํธ 9 ใ ํต๊ณผ (2.36ms, 10.6MB)
ํ
์คํธ 10 ใ ํต๊ณผ (0.53ms, 10.2MB)
ํ
์คํธ 11 ใ ํต๊ณผ (95.66ms, 53.4MB)
ํ
์คํธ 12 ใ ํต๊ณผ (117.54ms, 53.5MB)
ํ
์คํธ 13 ใ ํต๊ณผ (84.06ms, 53.4MB)
ํ
์คํธ 14 ใ ํต๊ณผ (89.90ms, 53.4MB)
ํ
์คํธ 15 ใ ํต๊ณผ (110.30ms, 53.5MB)
ํ
์คํธ 16 ใ ํต๊ณผ (89.00ms, 53.5MB)
ํ
์คํธ 17 ใ ํต๊ณผ (82.23ms, 53.5MB)
ํ
์คํธ 18 ใ ํต๊ณผ (141.29ms, 53.3MB)
ํ
์คํธ 19 ใ ํต๊ณผ (0.01ms, 10.2MB)
ํ
์คํธ 20 ใ ํต๊ณผ (0.01ms, 10.2MB)
ํ
์คํธ 21 ใ ํต๊ณผ (0.02ms, 10.2MB)
ํ
์คํธ 22 ใ ํต๊ณผ (0.02ms, 10.2MB)
ํ
์คํธ 23 ใ ํต๊ณผ (0.02ms, 10.2MB)
ํ
์คํธ 24 ใ ํต๊ณผ (0.03ms, 10.3MB)
ํ
์คํธ 25 ใ ํต๊ณผ (0.06ms, 10.4MB)
ํ
์คํธ 26 ใ ํต๊ณผ (0.20ms, 9.96MB)
ํ
์คํธ 27 ใ ํต๊ณผ (0.04ms, 10.4MB)
ํ
์คํธ 28 ใ ํต๊ณผ (0.05ms, 10.2MB)
ํ
์คํธ 29 ใ ํต๊ณผ (0.01ms, 10.2MB)
ํ
์คํธ 30 ใ ํต๊ณผ (0.41ms, 10.3MB)
ํ
์คํธ 31 ใ ํต๊ณผ (0.39ms, 10.2MB)
ํ
์คํธ 32 ใ ํต๊ณผ (0.06ms, 10.4MB)
ํ
์คํธ 33 ใ ํต๊ณผ (0.01ms, 10.1MB)
ํ
์คํธ 34 ใ ํต๊ณผ (0.02ms, 10.4MB)
ํ
์คํธ 35 ใ ํต๊ณผ (0.03ms, 10.3MB)
ํ
์คํธ 36 ใ ํต๊ณผ (0.02ms, 10.2MB)
'๊ฒ์ ํ๋ก๊ทธ๋๋ฐ > Python ํ๋ก๊ทธ๋๋ฐ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
ํ๋ก๊ทธ๋๋จธ์ค ๋ ํ ํฉ ๊ฐ๊ฒ ๋ง๋ค๊ธฐ (0) | 2023.02.16 |
---|---|
ํ๋ก๊ทธ๋๋จธ์ค ์ฐ๋ฐ์์ด ์ ์ ๋ถ (0) | 2023.02.15 |
ํ๋ก๊ทธ๋๋จธ์ค ํ ์ด๋ธ ํด์ ํจ์ (0) | 2023.02.15 |
ํ๋ก๊ทธ๋๋จธ์ค ๋ํ์ค ๊ฒ์ (0) | 2023.02.15 |
ํ๋ก๊ทธ๋๋จธ์ค ์ ์ฐ๊ธฐ (0) | 2023.02.14 |