본문 바로가기

Python(알고리즘,문제풀이)/BOJ(Bronze II)

백준 1978번 / 소수찾기 / Python

728x90

📚문제

출처 : 백준 1978(https://www.acmicpc.net/problem/1978)


📝풀이

# 1978번 소수찾기
n = int(input())
num_list = list(map(int,input().split()))
cnt = 0 

for num in num_list:
    for j in range(2,num+1):
        if num % j ==0:
            if num ==j:
                cnt += 1
            else:
                break
            
print(cnt)

 

2부터 해당숫자(num)까지

num_list 를 for문 돈다

 

자기 자신이 아닌 다른 수로 나누어지면 

반복문 종료(소수가 아니기 때문)

 

자기자신으로만 나누어진다면 

cnt += 1

 

728x90