#include #include #include #include #include int strToNum(std::string str) { int ret = 0; std::istringstream stream(str); stream >> ret; return ret; } bool isprime(int num) { if (num == 1 || num == 0) return false; if (num == 2) return true; for (int i = 2; i <= int(sqrt(num) + 1); ++i) { if (num % i == 0) return false; } return true; } int main() { std::string numStr; std::cin >> numStr; int startNum = strToNum(numStr); int maxCount = 0; std::set> visited; std::queue> queue; queue.push({numStr, 0}); visited.insert({numStr, 0}); while (!queue.empty()) { std::string currentStr = queue.front().first; int currentCount = queue.front().second; queue.pop(); int currentNum = strToNum(currentStr); if (isprime(currentNum)) { // std::cout << currentNum << std::endl; ++currentCount; } else { if (currentCount > maxCount) maxCount = currentCount; continue; } for(int i = 0; i < currentStr.length(); i++) { std::string novy(currentStr); novy.erase(i, 1); int xxxx = strToNum(novy); novy = std::to_string(xxxx); if(visited.insert({novy, currentCount}).second) queue.push({novy, currentCount}); } } std::cout << maxCount << std::endl; return 0; }