Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 | 31 |
Tags
- text2room
- 코딩테스트
- posterior distillation sampling
- Python
- 3d editing
- objectdrop
- 3d editting
- insturctnerf2nerf
- 논문리뷰
- 코테
- BOJ
- diffusion
- magic clothing
- VirtualTryON
- 3d gaussian splatting
- 네이버 부스트캠프 ai tech 6기
- Vit
- visiontransformer
- 3d generation
- 프로그래머스
- instructany2pix
- novel view synthesis
- text-to-video diffusion
- Programmers
- sound-to-image generation
- sonicdiffusion
- dreamfusion
- DP
- transformer
- dreamgaussian
Archives
- Today
- Total
평범한 필기장
[BOJ_Python] 21919_소수 최소 공배수 본문
https://www.acmicpc.net/problem/21919
21919번: 소수 최소 공배수
수열 중에 소수는 2, 3, 5가 있다.
www.acmicpc.net
import sys
n = int(input())
lst = list(map(int, sys.stdin.readline().split()))
def od(a):
if a == 1:
return 0
else:
for i in range(2, a):
if a % i == 0:
return 0
return 1
ans_lst = []
for k in lst:
if od(k) == 1:
ans_lst.append(k)
if len(ans_lst) == 0:
print(-1)
else:
cnt = 1
for k in ans_lst:
cnt *= k
print(cnt)
틀린 이유 : 시간 초과가 나서 뭐가 문제일까 생각을 했는데 중간에 소수를 구해서 소수의 최소 공배수를 구할 때, 소수를 빈 리스트에 넣고 그 리스트의 원소 전부를 곱하는 방식으로 코드를 짰다. 근데 보니까 굳이 이렇게 돌아갈 필요 없이 수열의 수들을 소수인지 판별하고 소수이면 1에 곱해가는 방식으로 간단하게 풀었어야 했다.
+ 수열의 중복을 없애야하기 때문에 list 말고 set으로 했어야 했다.
코드
import sys
import math
n = int(input())
lst = set(map(int, sys.stdin.readline().split()))
def od(a):
if a == 1:
return 0
else:
for i in range(2, a):
if a % i == 0:
return 0
return 1
ans = 1
for k in lst:
if od(k) == 1:
ans = ans * k
if ans == 1:
print(-1)
else:
print(ans)
'코딩 테스트 준비 > BOJ' 카테고리의 다른 글
[BOJ_Python] 11508_2+1 세일 (0) | 2023.03.19 |
---|---|
[BOJ_Python] 14916_거스름돈 (0) | 2023.03.18 |
[BOJ_Python] 2960_에라토스테네스의 체 (0) | 2023.03.15 |
[BOJ_Python] 9372_상근이의 여행 (0) | 2023.03.10 |
[BOJ_Python] 14675_단절점과 단절선 (0) | 2023.03.09 |