#include using namespace std; #define rep(i, a, b) for (int i = a; i < b; i++) #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() #define fo(i, n) rep(i, 0, n) #define F first #define S second #define MP make_pair typedef long long ll; typedef unsigned long long ull; typedef pair pii; typedef pair pll; typedef vector vi; typedef vector vll; ull modmul(ull a, ull b, ull M) { ull ret = a * b - M * ull(1.L / M * a * b); return ret + M * (ret < 0) - M * (ret >= (ll)M); } ull modpow(ll b, ll e, ll mod) { ull ans = 1; for (; e; b = modmul(b, b, mod), e /= 2) if (e & 1) ans = modmul(ans, b, mod); return ans; } bool isPrime(ull n) { if (n < 2 || n % 6 % 4 != 1) return (n | 1) == 3; ull A[] = {2, 325, 9375, 28178, 450775, 9780504, 1795265022}, s = __builtin_ctzll(n - 1), d = n >> s; for (ull a : A) { ull p = modpow(a % n, d, n), i = s; while (p != 1 && p != n - 1 && a % n && i--) p = modmul(p, p, n); if (p != n - 1 && i != s) return 0; } return 1; } constexpr ull tbl[] = {1, 10, 100, 1000, 10'000, 100'000, 1000'000, 10'000'000, 100'000'000, 1000'000'000, 10'000'000'000, 100'000'000'000}; ull digits(ull n) { ull count = 0; while (n > 0) { n /= 10; count++; } return count; } ull eat(ull n, ull dig) { return n % tbl[dig] + (n / tbl[dig + 1]) * tbl[dig]; } unordered_set visited; ull calc(ull n) { if (visited.find(n) != visited.end()) return 0; visited.insert(n); if (!isPrime(n)) return 0; ull digs = digits(n); ull best = 0; for (ull d = 0; d < digs; d++) { ull score = calc(eat(n, d)); best = max(score, best); } return best + 1; } int main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); ull orig; cin >> orig; cout << calc(orig) << endl; }