Skip to content

Commit 056d671

Browse files
committed
[level 1] Title: 소수 만들기, Time: 2.38 ms, Memory: 86 MB -BaekjoonHub
1 parent ed6ae1b commit 056d671

2 files changed

Lines changed: 90 additions & 0 deletions

File tree

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+
메모리: 86 MB, 시간: 2.38 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년 05월 19일 14:40:55
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: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
class Solution {
2+
public int solution(int[] nums) {
3+
int answer = 0;
4+
5+
for(int i=0; i<nums.length; i++){
6+
for(int j=i+1; j<nums.length; j++){
7+
for(int z=j+1; z<nums.length; z++){
8+
if(isPrime(nums[i]+nums[j]+nums[z])){
9+
answer++;
10+
}
11+
}
12+
}
13+
}
14+
15+
16+
return answer;
17+
}
18+
19+
boolean isPrime(int num){
20+
for(int i=2; i*i<=num; i++){
21+
if(num%i==0){
22+
return false;
23+
}
24+
}
25+
return true;
26+
}
27+
}

0 commit comments

Comments
 (0)