using System.Linq; using static System.Math; using System.Collections.Generic; using System; public class P { public string t { get; set; } public int p { get; set; } } public class Hello { static void Main() { var s = Console.ReadLine().Trim(); getAns(s); } static void getAns(string s) { var count = 0; var sL = s.Length; if (sL == 1) { Console.WriteLine(IsPrime(int.Parse(s)) ? 1 : 0); return; } var q = new Queue
(); var a = ""; q.Enqueue(new P { t = a + s[0], p = 0 }); q.Enqueue(new P { t = a + s[0] + ",", p = 0 }); while (q.Count() > 0) { var w = q.Dequeue(); if (w.p == sL - 1) { string[] line = w.t.Split(','); var ww = Array.ConvertAll(line, long.Parse).Sum(); if (IsPrime(ww)) count++; continue; } else { if (w.p == sL - 2) { q.Enqueue(new P { t = w.t + s[w.p + 1], p = w.p + 1 }); } else { q.Enqueue(new P { t = w.t + s[w.p + 1], p = w.p + 1 }); q.Enqueue(new P { t = w.t + s[w.p + 1] + ",", p = w.p + 1 }); } } } Console.WriteLine(count); } public static bool IsPrime(long n) { if (n < 2) return false; else if (n == 2) return true; else if (n % 2 == 0) return false; double sqrtNum = Sqrt(n); for (int i = 3; i <= sqrtNum; i += 2) if (n % i == 0) return false; return true; } }