#include #include #include using namespace std; vector sieve; int len(int n) { if(n == 0) return 0; return floor(log10(n)) + 1; } int rd(int n, int i) { int l = n / int(pow(10,i+1)); int r = n % int(pow(10,i)); return l * int(pow(10,i)) + r; } bool is_prime(int n) { if(n < 2) return false; for(int i = 2; i <= floor(sqrt(n)); i++) { if(n % i == 0) return false; } return true; } int maxl(int n) { int ln = len(n); int sum = 1; if(!is_prime(n)) return 0; if(ln == 1) return 1; int child_max = 0; for(int i = 0; i < ln; i++) { int child = rd(n,i); if(is_prime(child)) child_max = max(child_max, maxl(child)); } sum += child_max; return sum; } int main(){ int N; cin >> N; cout << maxl(N) << "\n"; return 0; sieve.push_back(-1); sieve.push_back(-1); for(int i = 2; i <= N; i++) sieve.push_back(i); for(int i = 2; i <= N; i++) { if(sieve[i] == -1) continue; for(int j = i*2; j <= N; j += i) { sieve[j] = -1; } } cout << maxl(N) << "\n"; }