#include #include #include #include #include using namespace std; unordered_map dp; bool isPrime(int num) { if (num == 1) { return false; } if (num == 2) { return true; } if ((num & 1) == 0) { return false; } int s = static_cast(sqrt(num)); for (int div = 3; div <= s; div += 2) { if (num % div == 0) return false; } return true; } int removeNthDigit(int num, int digit) { if (digit == 0) { return num / 10; } int base = static_cast(pow(10, digit)); int right = num % base; int left = num / (base * 10); return left * base + right; } int countDigits(int num) { int digit = 0; int base = 1; for (int i = 0; i < 32; ++i) { if (num / base == 0) { break; } ++digit; base *= 10; } return digit; } int findMaxPrimes(int num) { if (num == 0) { return 0; } if (dp.find(num) != dp.end()) { return dp[num]; } if (!isPrime(num)) { return 0; } int digits = countDigits(num); int best = 0; for (int i = 0; i < digits; ++i) { int withoutDigit = removeNthDigit(num, i); best = std::max(best, findMaxPrimes(withoutDigit)); } dp[num] = best + 1; return best + 1; } int main() { int num; cin >> num; cout << findMaxPrimes(num) << endl; }