#include #include #include #include #include using namespace std; unordered_set set; unordered_set primeGenerate (int cap){ vectorisPrime(cap + 1, true); for (int i = 2; i < sqrt(cap); i++){ if(!isPrime[i]) continue; for (int j = 2*i; j < cap; j+=i) { isPrime[j] = false; } } for (int i = 0; i < cap + 1; ++i) { if(isPrime[i]) { set.insert(i); } } return set; } int parseStringToNums(string num, int primesInRow, bool isFirst){ int numToInt = stoi(num); if(set.find(numToInt) == set.end()){ primesInRow++; if (num.length() == 1){ return primesInRow; } } else{ if(!isFirst) { return 0; } } int max_result = 0; for (int i = 0; i < num.size(); i++){ char new_string[num.size()]; int new_idx = 0; for (int j = 0; j < num.size(); ++j) { if(i==j) continue; new_string[new_idx] = num[j]; new_idx++; } max(max_result, parseStringToNums(new_string, primesInRow, false)); } return max_result; } int main() { string num; cin >> num; int stringToNum = stoi(num); unordered_set primes; primes = primeGenerate(stringToNum); int result = parseStringToNums(num, 0, true); cout << result << endl; return 0; }