File tree Expand file tree Collapse file tree 2 files changed +81
-0
lines changed
Expand file tree Collapse file tree 2 files changed +81
-0
lines changed Original file line number Diff line number Diff line change 1+ # [ level 1] 소수 찾기 - 12921
2+
3+ [ 문제 링크] ( https://school.programmers.co.kr/learn/courses/30/lessons/12921 )
4+
5+ ### 성능 요약
6+
7+ 메모리: 54 MB, 시간: 211.77 ms
8+
9+ ### 구분
10+
11+ 코딩테스트 연습 > 연습문제
12+
13+ ### 채점결과
14+
15+ 정확성: 75.0<br />효율성: 25.0<br />합계: 100.0 / 100.0
16+
17+ ### 제출 일자
18+
19+ 2025년 05월 16일 23:55:05
20+
21+ ### 문제 설명
22+
23+ <p >1부터 입력받은 숫자 n 사이에 있는 소수의 개수를 반환하는 함수, solution을 만들어 보세요. </p >
24+
25+ <p >소수는 1과 자기 자신으로만 나누어지는 수를 의미합니다.<br >
26+ (1은 소수가 아닙니다.)</p >
27+
28+ <h5 >제한 조건</h5 >
29+
30+ <ul >
31+ <li >n은 2이상 1000000이하의 자연수입니다.</li >
32+ </ul >
33+
34+ <h5 >입출력 예</h5 >
35+ <table class =" table " >
36+ <thead><tr>
37+ <th >n</th >
38+ <th >result</th >
39+ </tr >
40+ </thead >
41+ <tbody><tr>
42+ <td >10</td >
43+ <td >4</td >
44+ </tr >
45+ <tr >
46+ <td >5</td >
47+ <td >3</td >
48+ </tr >
49+ </tbody >
50+ </table>
51+ <h5 >입출력 예 설명</h5 >
52+
53+ <p >입출력 예 #1<br >
54+ 1부터 10 사이의 소수는 [ 2,3,5,7] 4개가 존재하므로 4를 반환</p >
55+
56+ <p >입출력 예 #2<br >
57+ 1부터 5 사이의 소수는 [ 2,3,5] 3개가 존재하므로 3를 반환</p >
58+
59+
60+ > 출처: 프로그래머스 코딩 테스트 연습, https://school.programmers.co.kr/learn/challenges
Original file line number Diff line number Diff line change 1+ class Solution {
2+ public int solution (int n ) {
3+ int answer = 0 ;
4+
5+ for (int i = 2 ; i <= n ; i ++){
6+ boolean chk = true ;
7+ for (int j = 2 ; j *j <= i ; j ++){ //배수 지우기
8+ if (i % j == 0 ){
9+ chk = false ;
10+ break ;
11+ }
12+ }
13+ if (chk ){
14+ answer ++;
15+ }
16+ }
17+
18+ return answer ;
19+
20+ }
21+ }
You can’t perform that action at this time.
0 commit comments