#include using namespace std; #define For(i, a, n) for(int i =a;i pii; template void dbg(Args&&... args){ ((cerr< pair operator+(const pair&a, const pair& b){ return {a.first +b.first, a.second + b.second}; } template ostream& operator<< (ostream& os, const pair& a){ return os<<"("< basic_ostream& operator<<(basic_ostream& os, const C&c){ for(auto it=begin(c); it!=end(c);++it){ os<<(it==begin(c)?"":" ")<<*it; } return os; } map memo; bool is_prime(int n){ if(n<=1)return false; For(i, 2, sqrt(n)+1){ if(n%i==0)return false; } return true; } int f(int n){ if(n == 0)return 0; if(memo.count(n))return memo[n]; int t =0; string s = to_string(n); if(!is_prime(n))return memo[n] = 0; // dbg("n is prime", n); For(i, 0, s.size()){ string ns = "0"; For(j, 0, s.size()){ if(j!=i)ns+=s[j]; } t = max(t, f(stoi(ns))); } return memo[n] = 1+ t; } void solve(){ int n;cin>>n; cout<sync_with_stdio(0); cin.exceptions(cin.failbit); int t=1;//cin>>t; while(t--){ solve(); } }