소수구하기 에라토스테네스의 체

2022. 5. 19. 17:35알고리즘

728x90

 

int prime[100]; // 소수 저장
int pn=0; // 소수의 개수 
bool check[101]={false,}; //false가 소수
int n =100; // 100까지 소수 체크
for(int i=2; i<=n; i++){
	if(check[i]==false){
    	prime[pn++] = i;
        for(int j=i*i; j<=n; j+=i){
        	check[j]=true;
        }
     }
 }

https://www.acmicpc.net/problem/1929

 

1929번: 소수 구하기

첫째 줄에 자연수 M과 N이 빈 칸을 사이에 두고 주어진다. (1 ≤ M ≤ N ≤ 1,000,000) M이상 N이하의 소수가 하나 이상 있는 입력만 주어진다.

www.acmicpc.net

출처 나무위키

 

https://visualgo.net/en

 

visualising data structures and algorithms through animation - VisuAlgo

VisuAlgo is free of charge for Computer Science community on earth. If you like VisuAlgo, the only "payment" that we ask of you is for you to tell the existence of VisuAlgo to other Computer Science students/instructors that you know =) via Facebook/Twitte

visualgo.net

알고리즘을 시각적으로 보여주는곳

728x90

'알고리즘' 카테고리의 다른 글

[C++][STL] map 사용법 정리  (0) 2022.05.30
최대 공약수, 최소 공배수 구하는 문제  (0) 2022.05.19
백준 1764 듣보잡 C++  (0) 2022.05.19
팰린드롬(회전문 문제)  (0) 2022.03.23
1.시간 복잡도 빅오 표기법 O(N)  (0) 2021.11.05