맛동산

(파이썬)백준 알고리즘 1978번 소수 찾기 본문

파이썬/알고리즘

(파이썬)백준 알고리즘 1978번 소수 찾기

오지고지리고알파고포켓몬고 2017. 11. 3. 17:00

백준 알고리즘 저지 1978번 문제 (https://www.acmicpc.net/problem/1978)



소수를 효율적으로 구하는 방법이 많은데 다시 찾기 귀찮아서 그냥 메모리에 쑤셔 넣었습니다.

아주 똥같은 코드란 뜻이죠




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
·¬
all=list(range(0,1001))¬
i=1¬
while·True:#i~<len()¬
····i·+=·1¬
····if·i·>·1000:·break¬
····if·all[i]==0:continue¬
····for·j·in·range(2,(1001//i)+1):¬
········if(i*j<1001):¬
············all[i*j]=0¬
¬
all=set(all).difference({0},{1})¬
#print(all)¬
count=0¬
a=int(input())¬
b=input().split()¬
for·i·in·b:¬
····if·int(i)·in·list(all):count+=1¬
print(count)¬
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Comments