소수 구하기 썸네일형 리스트형 [파이썬] 소수 구하기 import math ## Parameter # lst : 0~N까지의 자연수를 담은 리스트 def problem(lst): N = len(lst)-1 for i in range(2, math.floor(math.sqrt(N))+1): prime = True for j in range(2, math.floor(math.sqrt(i))+1): if i!=j and i%j==0: prime=False break if prime: for j in range(2, N//i+1): lst[i*j] = 0 return lst '에라토스테네스의 체'를 사용한 알고리즘 더보기 소수 구하기 지정한 범위 내에 있는 소수를 찾는 코드 static ArrayList primes = new ArrayList(); public static void main(String[] args) throws Exception { getPrimes(100); // 2~100에서 소수를 찾는다. System.out.println(primes); } public static void getPrimes(int end) { boolean isPrime = true; for(int i=2; i 더보기 이전 1 다음