import java.io.*; import java.util.*; import java.util.function.*; import java.util.stream.*; public class Main { static int ans = 0; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); char[] inputs = sc.next().toCharArray(); check(0, inputs, 0, 0); System.out.println(ans); } static void check(int idx, char[] inputs, long current, long value) { if (idx == inputs.length) { if (isPrime(current + value)) { ans++; } return; } int v = inputs[idx] - '0'; if (idx > 0) { check(idx + 1, inputs, v, current + value); } check(idx + 1, inputs, current * 10 + v, value); } static boolean isPrime(long x) { for (int i = 2; i <= Math.sqrt(x); i++) { if (x % i == 0) { return false; } } return true; } } class Scanner { BufferedReader br; StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() { try { br = new BufferedReader(new InputStreamReader(System.in)); } catch (Exception e) { } } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String next() { try { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } } catch (Exception e) { e.printStackTrace(); } finally { return st.nextToken(); } } }