Baekjoon 2960
에라토스테네스의 체


QUESTION ❔



CODE ⌨️

#include <iostream>
#include <cstring>

using namespace std;

bool prime[1001];

int N, K, cnt;

bool state = false;

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

	memset(prime, true, sizeof(prime));

	prime[0] = false;
	prime[1] = false;

	cin >> N >> K;

	for (int i = 2; i <= N; i++)
	{
		if (!prime[i]) continue;

		for (int j = i; j <= N; j = j + i)
		{
			if (prime[j])
			{
				prime[j] = false;

				if (K == ++cnt)
				{
					cout << j << "\n";
					state = true;

					break;
				}
			}
		}

		if (state) break;
	}

	return 0;
}



RESULT 💛



SIMPLE DISCUSSION ✏️

에라토스테네스의 체 관련 문제였다.



SOURCE 💎

Baekjoon_Link 👈 Click here


*****
NOT A TALENT ❎ NOT GIVING UP ✅
CopyRight ⓒ 2022 DCherish All Rights Reserved.