#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 * pow(10,i) + r; } int maxl(int n) { if(sieve[n] == -1) return 0; int ln = len(n); int sum = 1; //cout << n << ": " << sieve[n] << "\n"; if(ln == 1) return sum; int child_max = 0; for(int i = 0; i < ln; i++) { int child = rd(n,i); if(sieve[child] != -1) child_max = max(child_max,maxl(child)); } sum += child_max; //cout << "maxl " << n << " " << sum << "\n"; return sum; } int main(){ int N; cin >> N; 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 = 2; j <= N / i; j++) { sieve[i*j] = -1; } } cout << maxl(N) << "\n"; }