본문 바로가기

개발/algorithm

[백준 1978번] 소수 찾기 -python

문제 링크

https://www.acmicpc.net/problem/1978

 

1978번: 소수 찾기

첫 줄에 수의 개수 N이 주어진다. N은 100이하이다. 다음으로 N개의 수가 주어지는데 수는 1,000 이하의 자연수이다.

www.acmicpc.net

풀이 

- 백준 1929번 소수 구하기와 똑같은 방식으로 소수인지 판별해주었다. 

n = int(input())

data = list(map(int,input().split()))

cnt = 0 

for i in data:
  result = True 
  if i == 1 :
    continue
  else :
    for j in range(2, int(i** 0.5)+1):
      if i % j == 0:
        result = False 
        break
    if result :
      cnt += 1 

print(cnt)