Submission

Status:

xxxxxxxxxxxxxxxxxxxx

Subtask/Task Score:

0/100

Score: 0

User: PIXIX

Problemset: สุ่มสลับ

Language: cpp

Time: 0.004 second

Submitted On: 2026-03-19 12:24:09

#include <algorithm>
#include <cmath>
#include <ios>
#include <iostream>
#include <string>
#include <type_traits>
#include <vector>
using namespace std;
const int MAXCAP = 1000000;
vector<bool> primecheck(MAXCAP+5,true);

void set_prime(){
    int sq = (int) sqrt(MAXCAP);
    primecheck[0] = false;
    primecheck[1] = false;
    for(int i = 4; i <= MAXCAP;i+=2)primecheck[i]=false;
    for(int i = 3;i <= sq;i+=2){
        if(primecheck[i]) {
            for(int j = i*i; j <= MAXCAP;j+=2 * i){
                primecheck[j] = false;
            }
        }
    }
    //for(int i = 0 ; i <= 100;i++) if(primecheck[i]) cout << i << " ";
}

void premu(vector<string> nums){
    for(string &str : nums){
        int c = 0;
        sort(str.begin(),str.end());
        do{
            if(primecheck[(int) stoi(str)]){
                c++;
            }
        }while(next_permutation(str.begin(),str.end()));
        cout << c << '\n';
    }
}

int main (int argc, char *argv[]) {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int m,n; cin>>m>>n;
    vector<string> vec(m);

    for(int i = 0;i < m;i++){
        cin>>vec[i];
    }
    set_prime();
    premu(vec);

    return 0;
}