Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | |||||
| 3 | 4 | 5 | 6 | 7 | 8 | 9 |
| 10 | 11 | 12 | 13 | 14 | 15 | 16 |
| 17 | 18 | 19 | 20 | 21 | 22 | 23 |
| 24 | 25 | 26 | 27 | 28 | 29 | 30 |
| 31 |
Tags
- BFS
- 문자열
- 자바
- BOJ
- 문제풀이
- 백준
- COS PRO
- math
- 코테
- greedy
- MySQL
- Java
- DP
- db
- 알고리즘
- priorityqueue
- 코딩테스트
- 이분탐색
- oracle
- 프로그래머스
- dfs
- SQL
- 러닝일지
- SWEA
- 문제해결
- binary search
- 운동기록
- 투포인터
- 건강
- 시뮬레이션
Archives
- Today
- Total
슈콩
[프로그래머스] Lv.1 소수 찾기 본문


[문제]
https://school.programmers.co.kr/learn/courses/30/lessons/12921
프로그래머스
SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
[소스 코드]
class Solution {
public int solution(int n) {
boolean[] composite = new boolean[n+1];
composite[1] = true;
for(int i=2;i*i<=n;i++){
for(int j=i*i;j<=n;j+=i){
if(!composite[j]){
composite[j] = true;
}
}
}
int answer = 0;
for(int i=2;i<=n;i++){
if(!composite[i]) answer++;
}
return answer;
}
}'Algorithms > Programmers' 카테고리의 다른 글
| [프로그래머스] Lv.1 문자열 내 마음대로 정렬하기 (0) | 2025.10.11 |
|---|---|
| [프로그래머스] Lv.1 크기가 작은 부분 문자열 (0) | 2025.10.11 |
| [프로그래머스] Lv.3 입국 심사 (0) | 2025.10.09 |
| [프로그래머스] Lv.1 예산 (0) | 2025.10.09 |
| [프로그래머스] Lv.1 체육복 (0) | 2025.10.09 |