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