문제

https://www.acmicpc.net/problem/1929
1929번: 소수 구하기
첫째 줄에 자연수 M과 N이 빈 칸을 사이에 두고 주어진다. (1 ≤ M ≤ N ≤ 1,000,000) M이상 N이하의 소수가 하나 이상 있는 입력만 주어진다.
www.acmicpc.net
코드
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int m,n;
cin >> m >> n;
for(int i=m; i<=n; i++){
bool flag = true;
for(int j=2; j<=sqrt(i); j++){
if(i%j == 0){
flag = false;
break;
}
}
if(i!=1 && flag) cout << i << '\n';
}
return 0;
}
정리
참조
'Beakjoon > math' 카테고리의 다른 글
| [백준] 1735번 분수 합 (C++) - Euclidean algorithm (0) | 2022.06.10 |
|---|---|
| [백준] 6588번 골드바흐의 추측 (C++) (0) | 2022.04.01 |
| [백준] 17425번 약수의 합 (C++) (0) | 2022.03.25 |
| [백준] 17427번 약수의 합2 (C++) (0) | 2022.03.22 |
| [백준] 4375번 1 (C++) - modular 연산 (0) | 2022.03.21 |