입력
첫째 줄에 자연수 n, m이 주어진다. (1≤n,m≤20,000)
출력
첫째 줄에 n부터 m까지 존재하는 소수를 모두 출력한다.
예시
1 10
2 3 5 7
#include <iostream>
using namespace std;
int main() {
int first,second;
bool check= true;
cin >> first>>second;
for(int i=first ; i <= second ;i++)
{
for(int j=2;j<i;j++)
{
if(i%j==0)
{
check = false;
break;
}
}
if(check && i!=1)
{
cout<<to_string(i)+" ";
}
check = true;
}
cout << "\n";
}
'알고리즘' 카테고리의 다른 글
C++ 재귀 (0) | 2018.12.24 |
---|---|
C++ 뒤집기 ( 2차 배열 함수 파라미터 ) (0) | 2018.12.24 |
C++ 카드게임 (0) | 2018.12.20 |
C++ 두번째로 작은 수 찾기 (0) | 2018.12.20 |
C++ 별찍기 (0) | 2018.12.18 |
댓글