
1일차 문제
링크 : https://www.acmicpc.net/problem/1929
문제 풀이
기본적인 소수를 구하는 문제
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int M = Integer.parseInt(st.nextToken());
int N = Integer.parseInt(st.nextToken());
for(int i=M; i<=N; i++) {
if(isPrime(i)) {
System.out.println(i);
}
}
}
private static boolean isPrime(int num) {
if(num < 2) {
return false;
}
for(int i=2; i<=Math.sqrt(num); i++) {
if(num % i == 0) {
return false;
}
}
return true;
}
}
'Study > 99클럽 코테 스터디' 카테고리의 다른 글
| [99클럽 코테 스터디 6일차 TIL] 섬의 개수 (0) | 2025.04.07 |
|---|---|
| [99클럽 코테 스터디 5일차 TIL] 수열 (0) | 2025.04.04 |
| [99클럽 코테 스터디 4일차 TIL] 안전 영역 (0) | 2025.04.03 |
| [99클럽 코테 스터디 3일차 TIL] 바탕화면 정리 (0) | 2025.04.02 |
| [99클럽 코테 스터디 2일차 TIL] 피보나치 비스무리한 수열 (0) | 2025.04.01 |