Submission
Status:
PPPPPxxPxx
Subtask/Task Score:
60/100
Score: 60
User: NovemNotes
Problemset: การเรียงสับเปลี่ยน
Language: cpp
Time: 0.461 second
Submitted On: 2026-03-13 15:44:38
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 100000009;
int q,n;
bitset<N> check;
int convert(string s){
int num=0;
for(int i=s.size()-1;i>=0;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";
if(!check[convert(s)])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;
}