Submission
Status:
PPPPPxxPxx
Subtask/Task Score:
60/100
Score: 60
User: navysrimuang
Problemset: การเรียงสับเปลี่ยน
Language: cpp
Time: 0.007 second
Submitted On: 2026-01-15 14:34:12
#include<bits/stdc++.h>
using namespace std;
int main(){
int t,n;
cin >> t >> n;
const int MX = 1000000;
vector<bool> sieve(MX+1,1);
sieve[0] = sieve[1] = 0;
for(int i = 2;i*i<=MX;i++){
if(sieve[i]){
for(int j = 2*i;j<=MX;j+=i){
sieve[j] = 0;
}
}
}
while(t--){
string s;
cin >> s;
sort(s.begin(),s.end());
int cnt = 0;
do{
int d = stoi(s);
if(sieve[d]){
cnt++;
}
}while(next_permutation(s.begin(),s.end()));
cout << cnt << "\n";
}
return 0;
}