Submission

Status:
PPPPPxxPxx

Score: 60

User: YoruoniVamp

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

Language: cpp

Time: 0.006 second

Submitted On: 2025-03-30 21:38:37

// YoruoniVamp - VTUBE
// Pragma Credit to Discord: pxsithexahydride
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,no-stack-protector,inline-small-functions,inline,unsafe-math-optimizations,omit-frame-pointer,inline-functions-called-once")
#include <bits/stdc++.h>
#pragma GCC target("avx2,fma,popcnt,lzcnt,bmi,bmi2,sse4.2,tune=native")
using namespace std;
#define endl '\n'
#define ll long long
#define ld long double
#define ull unsigned ll
#define cint const int
#define cf const float

cint mxA = 1e6+5, MOD = 1e9+7, INF = 0x3f3f3f3f;
cint d4x[4] = {0, 1, 0, -1}, d4y[4] = {1, 0, -1, 0};
cint d8x[8] = {0, 1, 1, 1, 0, -1, -1, -1}, d8y[8] = {1, 1, 0, -1, -1, -1, 0, 1};

void wait(int ms){
    clock_t endwait;
    endwait = clock() + ms;
    while(clock()<endwait){}
}

bool isPrime(int n){
    for(int i = 2; i <= sqrt(n); i++){
        if(n%i==0) return false;
    }return true;
}

void solve(){
    int m, n; cin >> m >> n;
    while(m--){
        string s; cin >> s;
        sort(s.begin(),s.end());
        int cnt = 0;
        // cout << "q: " << m << endl;
        do{
            int a = stoi(s);
            // cout << a << endl;
            if(isPrime(a)) cnt++;
        }while(next_permutation(s.begin(),s.end()));
        cout << cnt << endl;
    }
    return;
}

int main(){
    cin.tie(nullptr)->sync_with_stdio(0);cout.tie(0);
    // freopen("", "r", stdin);
    // freopen("", "w", stdout);
    int t = 1;
    // cin >> t;
    while(t--) solve();
    return 0;
}