/* -*- coding: utf-8 -*- * * 1747.cc: No.1747 Many Formulae 2 - yukicoder */ #include #include #include using namespace std; /* constant */ const int MAX_N = 10; const int MAX_K = MAX_N - 1; const int KBITS = 1 << MAX_K; /* typedef */ typedef long long ll; /* global variables */ char s[MAX_N + 4]; /* subroutines */ bool isprime(ll x) { for (int p = 2; (ll)p * p <= x; p++) if (x % p == 0) return false; return true; } /* main */ int main() { scanf("%s", s); int n = strlen(s); int k = n - 1, kbits = 1 << k; int cnt = 0; for (int bits = 0; bits < kbits; bits++) { ll sum = 0, c = s[0] - '0'; for (int i = 0, bi = 1; i < k; i++, bi <<= 1) { if (bits & bi) sum += c, c = s[i + 1] - '0'; else c = c * 10 + (s[i + 1] - '0'); } sum += c; //printf("%lld\n", sum); if (isprime(sum)) cnt++; } printf("%d\n", cnt); return 0; }