Submission
Status:
PPPPPxxPxx
Subtask/Task Score:
60/100
Score: 60
User: purihorharin
Problemset: การเรียงสับเปลี่ยน
Language: cpp
Time: 0.006 second
Submitted On: 2026-03-19 20:41:25
#include <iostream>
#include <algorithm>
#include <bitset>
#include <cmath>
std::bitset<1000000> bs;
int main () {
int n, m;
std::cin >> n >> m;
int pow_10_m = pow(10, m);
bs[0] = bs[1] = 1;
for (int i = 2; i * i <= pow_10_m; i++) {
if (bs[i]) continue;
for (int j = i + i; j < pow_10_m; j+=i) {
bs[j] = 1;
}
}
for (int i = 0; i < n; i++) {
std::string buf;
std::cin >> buf;
std::sort(buf.begin(), buf.end());
int count = 0;
do {
count += !(bs[std::stoi(buf)]);
} while (std::next_permutation(buf.begin(), buf.end()));
std::cout << count << "\n";
}
}