Submission

Status:

PPPPPxxPxx

Subtask/Task Score:

60/100

Score: 60

User: theem1502

Problemset: การเรียงสับเปลี่ยน

Language: cpp

Time: 0.051 second

Submitted On: 2026-03-13 20:52:53

#include <bits/stdc++.h>
using namespace std;
const int thecons = 10000000;
int t, n;


void solve(vector<bool> &sieve) {
    string thenum;
    cin >> thenum;
    sort(thenum.begin(), thenum.end());
    int cnt = 0;
    int firstnum = stoi(thenum);
    if (!sieve[firstnum]) cnt++;
   // vector<int> temp(3,3);
    while(next_permutation(thenum.begin(), thenum.end())) {
        //    cout << "yes " << thenum << "\n";
        int realnum = stoi(thenum);
        if (!sieve[realnum]) {/*cout << "haha";*/ cnt++;}
    }
    cout << cnt << "\n";
}

int main() {
    cin >> t >> n;
    vector<bool> sieve(thecons, false);
    sieve[1] = true;
    sieve[0] = true;
    for (int i = 2; i < thecons; i++) {
        if (sieve[i] == false) {
          //      cout << "w";
            for (int j = 2*i; j < thecons; j+= i) sieve[j] = true;
        }
    }
    //cout << "t";
    /*
    for (int i = 0; i < 100; i++) {
        cout << sieve[i] << " "
;

    }
cout << "\n";*/
    while(t--) {
        solve(sieve);
    }
}