링크 : https://school.programmers.co.kr/learn/courses/30/lessons/42839
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
bool isPrime(int n){
if (n < 2) return false;
for(int i = 2; i*i <= n; i++){
if(n % i == 0) return false;
}
return true;
}
int solution(string numbers) {
int answer = 0;
vector<int> v;
for(int i = 0; i < numbers.size(); i++){
v.push_back(numbers[i] - '0');
}
sort(v.begin(),v.end());
vector<int> ans;
do{
for(int i = 0; i <= v.size(); i++){
int tmp = 0;
for(int j = 0; j < i; j++){
tmp = (tmp * 10) + v[j];
ans.push_back(tmp);
}
}
} while(next_permutation(v.begin(), v.end()));
sort(ans.begin(), ans.end());
ans.erase(unique(ans.begin(), ans.end()), ans.end());
for(int i = 0; i < ans.size(); i++){
if(isPrime(ans[i])) answer += 1;
}
return answer;
}