#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cstdlib>
using namespace std;
int stringcheck(int num,string numbers)//가능한 문자인지 판결(가능하면 0,불가능하면 1)
{
int check;
string strNum = to_string(num);
for(int i=0;i<strNum.size();i++)
{
check = 1;
for(int j =0;j<numbers.size();j++)
{
if(strNum.at(i)==numbers.at(j))
{
check = 0;
numbers.at(j) = ' ';
break;
}
}
if(check == 1)
{
return 1;
}
}
return 0;
}
int solution(string numbers) {
int answer = 0;
sort(numbers.begin(),numbers.end(),greater<int>());
int max = stoi(numbers);
vector<int> arr(10000000);
for(int i = 0;i<=arr.size();i++)
{
arr[i]=1;
}
for(int i = 2;i<=arr.size();i++)
{
for(int j =i*i;j<=arr.size();j=j+i)
{
arr[j] = 0;
}
}
for(int i = 2;i<=max;i++)
{
if(arr[i]==1&&stringcheck(i,numbers)==0)
{
answer++;
}
}
return answer;
}