Submission
Status:
PPPPP--P--
Subtask/Task Score:
60/100
Score: 60
User: NovemNotes
Problemset: การเรียงสับเปลี่ยน
Language: cpp
Time: 0.488 second
Submitted On: 2026-03-13 16:00:27
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 100000009;
int q,n;
bitset<100000009> check;
int convert(string s){
int num=0;
for(int i=0;i<n;i++){
num = (num*10)+(s[i]-'0');
}
return num;
}
void solve(string s){
sort(s.begin(),s.end());
int ans=0;
do{
// cout << s << "\n";
int num = convert(s);
if(num>=0 && num < N && !check[num])ans++;
}while(next_permutation(s.begin(),s.end()));
cout << ans << "\n";
}
int32_t main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
check[0]=check[1]=1;
for(int i=2;i<N;i++){
if(check[i])continue;
for(int j=i+i;j<N;j+=i)check[j]=1;
}
cin >> q >> n;
while(q--){
string s;cin >> s;
solve(s);
}
return 0;
}