-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPro12977.java
More file actions
33 lines (28 loc) · 876 Bytes
/
Pro12977.java
File metadata and controls
33 lines (28 loc) · 876 Bytes
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
32
33
package algorithm_study.programers;
import java.util.Arrays;
// 소수 만들기 - https://school.programmers.co.kr/learn/courses/30/lessons/12977
public class Pro12977 {
public int solution(int[] nums) {
Arrays.sort(nums);
int count = 0;
for(int i = 0; i < nums.length - 2; i++) {
for(int j = i + 1; j < nums.length - 1; j++) {
for(int k = j + 1; k < nums.length; k++) {
int sum = nums[i] + nums[j] + nums[k];
if(isPrime(sum)) {
count++;
}
}
}
}
return count;
}
public boolean isPrime(int sum) {
for (int prime = 2; prime <= Math.sqrt(sum); prime++) {
if(sum % prime == 0) {
return false;
}
}
return true;
}
}