본문 바로가기
  • Let's study
PS/백준

[C++] 백준 1929번: 소수 구하기

by 코딩고수이고파 2020. 11. 22.
#include<iostream>
#include<algorithm>

using namespace std;

int arr[1000001] = { 0, };

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	int m, n;
	cin >> m >> n;

	arr[0] = 1; arr[1] = 1;

	for (int i = 2; i <= n; i++) {
		for (int j = 2; j*i <= n; j++) {
			arr[i*j] = 1;
		}
	}
	for (int i = m; i <= n; i++) {
		if (arr[i] == 0)
			cout << i << '\n';
	}
}

댓글