#include #include #include #include using namespace std; bool is_prime(int num) { if (num == 1) return false; if (num == 2) return true; for (int i = 3; i < std::sqrt(num); i += 2) if (num % i == 0) return false; return true; } void rec ( string a, int& b, int c ){ if ( !is_prime(stoi( a ) ) ){ return; } set< int > tmp; c = c + is_prime( stoi( a ) ); if ( a.length() == 1 ){ if ( c > b ){ b = c; } return; } for ( int i = 0; i < a.length(); i++ ){ string tmpstr; for ( int x = 0; x < a.length(); x++ ){ if ( x != i ){ tmpstr.push_back( a[ x ] ); } } tmp.insert(stoi(tmpstr) ); } for ( auto x : tmp ){ rec(to_string(x), b, c ); } } int main() { int a, b = 0; cin >> a; rec (to_string( a ), b, 0 ); cout << b << endl; return 0; }