728x90
[문제]
https://www.acmicpc.net/problem/1978
1978번: 소수 찾기
첫 줄에 수의 개수 N이 주어진다. N은 100이하이다. 다음으로 N개의 수가 주어지는데 수는 1,000 이하의 자연수이다.
www.acmicpc.net
[코드]
n = int(input())
arr = list(map(int,input().split()))
#소수인지 판별하는 함수
def isPrime(x):
cnt = 0
for i in range(2,x):
if x % i == 0:
cnt += 1
break
return 1 if cnt == 0 else 0
#main
result = 0
for i in arr:
if isPrime(i) == 1 and i != 1:
result += 1
print(result)
반응형
'🚩 Coding Test > Baekjoon' 카테고리의 다른 글
[BOJ][Python] 11653 소인수분해 (0) | 2024.04.09 |
---|---|
[BOJ][Python] 2581 소수 (0) | 2024.04.09 |
[BOJ][Python] 2644 촌수계산 (0) | 2024.04.08 |
[BOJ][Python] 2606 바이러스 (0) | 2024.04.08 |
[BOJ][Python] 1260 DFS와 BFS (0) | 2024.04.08 |