Skip to content

Commit 52264df

Browse files
committed
[level 1] Title: 소수 만들기, Time: 2.44 ms, Memory: 75.4 MB -BaekjoonHub
1 parent 932a8c1 commit 52264df

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# [level 1] 소수 만들기 - 12977
2+
3+
[문제 링크](https://school.programmers.co.kr/learn/courses/30/lessons/12977)
4+
5+
### 성능 요약
6+
7+
메모리: 75.4 MB, 시간: 2.44 ms
8+
9+
### 구분
10+
11+
코딩테스트 연습 > Summer/Winter Coding(~2018)
12+
13+
### 채점결과
14+
15+
정확성: 100.0<br/>합계: 100.0 / 100.0
16+
17+
### 제출 일자
18+
19+
2025년 07월 18일 22:04:27
20+
21+
### 문제 설명
22+
23+
<p>주어진 숫자 중 3개의 수를 더했을 때 소수가 되는 경우의 개수를 구하려고 합니다. 숫자들이 들어있는 배열 nums가 매개변수로 주어질 때, nums에 있는 숫자들 중 서로 다른 3개를 골라 더했을 때 소수가 되는 경우의 개수를 return 하도록 solution 함수를 완성해주세요.</p>
24+
25+
<h5>제한사항</h5>
26+
27+
<ul>
28+
<li>nums에 들어있는 숫자의 개수는 3개 이상 50개 이하입니다.</li>
29+
<li>nums의 각 원소는 1 이상 1,000 이하의 자연수이며, 중복된 숫자가 들어있지 않습니다.</li>
30+
</ul>
31+
32+
<hr>
33+
34+
<h5>입출력 예</h5>
35+
<table class="table">
36+
<thead><tr>
37+
<th>nums</th>
38+
<th>result</th>
39+
</tr>
40+
</thead>
41+
<tbody><tr>
42+
<td>[1,2,3,4]</td>
43+
<td>1</td>
44+
</tr>
45+
<tr>
46+
<td>[1,2,7,6,4]</td>
47+
<td>4</td>
48+
</tr>
49+
</tbody>
50+
</table>
51+
<h5>입출력 예 설명</h5>
52+
53+
<p>입출력 예 #1<br>
54+
[1,2,4]를 이용해서 7을 만들 수 있습니다.</p>
55+
56+
<p>입출력 예 #2<br>
57+
[1,2,4]를 이용해서 7을 만들 수 있습니다.<br>
58+
[1,4,6]을 이용해서 11을 만들 수 있습니다.<br>
59+
[2,4,7]을 이용해서 13을 만들 수 있습니다.<br>
60+
[4,6,7]을 이용해서 17을 만들 수 있습니다.</p>
61+
62+
63+
> 출처: 프로그래머스 코딩 테스트 연습, https://school.programmers.co.kr/learn/challenges
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution {
2+
public static boolean isPrime(int num) {
3+
if (num < 2) return false;
4+
for (int i = 2; i <= Math.sqrt(num); i++) {
5+
if (num % i == 0) return false;
6+
}
7+
return true;
8+
}
9+
10+
public int solution(int[] nums) {
11+
int answer = 0;
12+
for (int i = 0; i < nums.length; i++) {
13+
for (int j = i+1; j < nums.length; j++) {
14+
for (int z = j+1; z < nums.length; z++) {
15+
int current = nums[i] + nums[j] + nums[z];
16+
if (isPrime(current)) answer++;
17+
}
18+
}
19+
}
20+
return answer;
21+
}
22+
}

0 commit comments

Comments
 (0)