Submission

Status:

-----TT-TT

Subtask/Task Score:

0/100

Score: 0

User: nga12345

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

Language: cpp

Time: 1.098 second

Submitted On: 2025-10-11 09:21:57

#include<bits/stdc++.h>
using namespace std;

vector<int> permutations;
int c, length;

int checkPrime(int x) {
    for (int i = 2; i * i < x; i++) {
        if (x % i == 0) return 0;
    }

    return 1;
}

void findPermutation(string list, string cur) {    
    if (list.empty()) {
        cout << cur << endl;
        permutations.push_back(atoi(cur.c_str()));
        return;
    };
    
    for (int i = 0; i < list.length(); i++) {
        char x = list[i];
        string z = cur;

        string y = list;
        y.erase(i, 1);

        z += x;
        
        findPermutation(y, z);
    }
}

int main() {
    cin >> c >> length;

    for (int i = 0; i < c; i++) {
        permutations.clear();

        string x;
        cin >> x;

        findPermutation(x, "");
        int c = 0;
        for (int i = 0; i < x.length(); i++) {
            if (checkPrime(permutations[i])) c++;
        }

        cout << c << endl;
    }
}