https://programmers.co.kr/learn/courses/30/lessons/12977
#include <vector>
#include <iostream>
using namespace std;
vector<int> per(3);
int count = 0;
bool check[51] = { false, };
void permutation(int depth, vector<int> num, int idx){
if(depth == 3){
int sum = 0;
for(int i=0;i<3;i++){
sum += per[i];
}
for(int i = 2;i<sum;i++){
if(sum%i ==0)
break;
if(i == sum-1)
count++;
}
return;
}
for(int i = idx; i < num.size(); i++){
if(!check[i]){
check[i] = true;
per[depth] = num[i];
permutation(depth + 1, num, i+1);
check[i] = false;
}
}
}
int solution(vector<int> nums) {
permutation(0, nums, 0);
return count;
}
#include <vector>
#include <iostream>
using namespace std;
bool check(int n){
for(int i=2;i<n/2;i++)
if(n%i==0)
return false;
return true;
}
int solution(vector<int> nums) {
int answer = 0;
int N=nums.size();
for(int i=0;i<N;i++)
for(int j=i+1;j<N;j++)
for(int k=j+1;k<N;k++){
if(check(nums[i]+nums[j]+nums[k]))
answer++;
}
return answer;
}