본문 바로가기

라이브러리/JAVA

에라체

 

 

static ArrayList<Integer> Sieve_Of_Eratosthenes (int N)
{
    ArrayList<Integer> al = new ArrayList<>();
    boolean[] check = new boolean[N+1];

    for (int i=2; i*i<=N; i++)
    {
        if ( check[i] == false )
        {
            for (int j=i*i; j<=N; j+=i)
                check[j] = true;
        }
    }

    for (int i=2; i<=N; i++)
    {
        if ( check[i] == false )
            al.add(i);
    }

    return al;
}

'라이브러리 > JAVA' 카테고리의 다른 글

벨만 포드  (2) 2024.07.28
히스토그램 최대 넓이  (0) 2024.07.15
분할정복 거듭제곱  (1) 2024.07.08
플로이드 워셜  (1) 2024.07.03
다익스트라  (0) 2024.06.24