728x90
뭔 문제인지 모르겠다. 당연히 시간 초과 날 것 같어서 소인수분해 함수를 이용해서 했지만 시간 초과가 났고, 그냥 math.gcd 를 사용하니 풀렸다.
import sys
import math
from collections import Counter
def sosu(x):
d = 2
answer = [ ]
while d <= x:
if x % d == 0:
answer.append(d)
x = x / d
else:
d = d + 1
return answer
q = 1
w = 1
a = int(input())
first = list(map(int,sys.stdin.readline().split(" ")))
for i in first:
q*=i
b = int(input())
second = list(map(int,sys.stdin.readline().split(" ")))
for i in second:
w*=i
"""
one = [ ]
two = [ ]
for i in range(0,len(first)):
k = sosu(first[i])
for j in k:
one.append(j)
for i in range(0,len(second)):
k = sosu(second[i])
for j in k:
two.append(j)
answer = [ ]
for i in one:
if i in two:
answer.append(i)
two.remove(i)
ans = 1
/for i in answer:
// ans *= i
"""
ans = math.gcd(q,w)
if len(str(ans))>9:
print(str(ans)[-9:])
else:
print(ans)
728x90
'🟢 알고리즘 문제 풀이 > Baekjoon' 카테고리의 다른 글
| [파이썬] 백준 17610 양팔 저울 (0) | 2023.04.04 |
|---|---|
| [파이썬] 백준 1527 금만수의 개수 (0) | 2023.03.29 |
| [파이썬] 백준 2502 떡 먹는 호랑이 (0) | 2023.03.29 |
| [파이썬] 백준 2564 경비원 (0) | 2023.03.25 |
| [파이썬] 백준 1309 동물원 (0) | 2023.03.25 |