😈 알고리즘/💻 백준
💻 1929번 문제 : 소수 구하기 🤔
Buᐢ༝ᐢy
2022. 11. 18. 06:00
1929번: 소수 구하기


#include <iostream>
using namespace std;
bool isPrimeNumber(int p_Int)
{
if(p_Int < 2) return false;
for(int i = 2; i * i <= p_Int; i++)
{
if(p_Int % i == 0) return false;
}
return true;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int M = 0;
int N = 0;
int length = 0;
cin >> M >> N;
length = N - M +1;
for(int i =0; i < length; i++)
{
if(isPrimeNumber(M) == true) cout << M << '\n';
M++;
}
}
메모리 (KB) | 시간 (ms) | 코드 길이 (B) |
2020 | 188 | 518 |
🤔 다시 풀어보기
이전에 풀었던 소수 문제들을 상기하며 풀어보았다. 아쉬운 점은 시간이 생각보다 걸리는 것인데, ios_base::sync_with_stdio(false);
, cin.tie(NULL);
을 해주어도 차이가 없었다. 다른 방법들이 있을 거 같은데 추후에 시간을 줄여보도록 해야 겠다.
Uploaded by N2T