Skip to content

Commit

Permalink
#2 : 1978_소수 찾기.py
Browse files Browse the repository at this point in the history
  • Loading branch information
devCharlotte committed Apr 8, 2023
1 parent b7ce423 commit d7053ee
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions 이티준희/1978_소수 찾기.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#2023-04-08-Week1-과제
#1978_소수 찾기

'''
입력 1 - 수의 개수 N < 100
입력 2 - 1000 이하의 자연수 N개
결과 - 입력2의 자연수 중 소수의 개수 출력
'''

#입력 받는 값 여러 개 -> map 함수


n = int(input("입력 : \n"))

num = list(map (int, input().split())) # 자료형, 함수 (.split() 공백으로 구분)

result = 0 # 입력한 자연수 중 소수의 개수

for i in num : # 입력 받은 수들을 소수 확인 대상 i로 설정
cnt = 0 # 소수 확인 대상의 약수 개수
if i == 1 : # 1은 소수 아님
continue

for j in range (2, i+1) : # 2~i까지
if (i%j == 0) : # 소수 확인 대상이 2부터 자기 자신으로 나눴을 때 0 이 되면
cnt += 1 # 약수 개수 증가

if cnt == 1 : # 약수의 개수 1개
result += 1 # 소수 개수 추가

print ("출력 : ", result) # 출력 : 입력 자연수 중 소수의 개수









0 comments on commit d7053ee

Please sign in to comment.