#include using namespace std; #define ll long long unordered_map primes; bool isPrime(int value){ if (value <= 2) return false; if (value % 2 == 0) return false; if (value % 3 == 0) return false; if(primes.find(value) != primes.end()){ return primes[value]; } int sq = sqrt(value); for(int i = 3; i <= sq; i+=2){ if(value % i == 0) return false; } return true; }; int result = 0; void rec(int prime, int cnt){ if(!isPrime(prime)){ primes[prime] = false; result = max(result, cnt); return; } cnt++; primes[prime] = true; auto stringPrime = to_string(prime); for(int toRemove = 0; toRemove < stringPrime.length(); toRemove++){ auto cpy = stringPrime; cpy = cpy.erase(toRemove, 1); auto next = atoi(cpy.c_str()); rec(next, cnt); } } int main(){ int n; cin >> n; auto stringPrime = to_string(n); auto isPrimeStart = isPrime(n); for(int toRemove = 0; toRemove < stringPrime.length(); toRemove++){ auto cpy = stringPrime; cpy.erase(toRemove, 1); auto next = atoi(cpy.c_str()); rec(next, isPrimeStart); } cout << result << endl; return 0; }