using System; using System.Collections.Generic; public class Program { public void Proc() { Reader.IsDebug = false; int min = int.Parse(Reader.ReadLine()); int max = int.Parse(Reader.ReadLine()); this.CreatePrimeList(min,max); int maxLength = 1; int startIdx = 0; int ans = -1; Dictionary hashCount = new Dictionary(); hashCount[HashList[0]] = 1; for(int i=0; i= maxLength) { ans = PrimeList[startIdx]; maxLength = hashCount.Count; } } if(maxLength == 1) { ans = PrimeList[PrimeList.Count - 1]; } Console.WriteLine(ans); } private List PrimeList = new List(); private List HashList = new List(); private void CreatePrimeList(int min, int max) { bool[] isProc = new bool[max + 1]; for(int i=2; i<=max; i++) { if (isProc[i] == false) { isProc[i] = true; if(i >= min) { PrimeList.Add(i); int tmpNum = i; while (tmpNum >= 10) { int total = 0; string strTemp = tmpNum.ToString(); foreach (char c in strTemp) { total += int.Parse(c.ToString()); } tmpNum = total; } HashList.Add(tmpNum); } for (int j = 1; j<=max / i; j++) { isProc[i * j] = true; } } } } public class Reader { private static String InitText = @" 10 100 "; private static System.IO.StringReader sr = null; public static bool IsDebug = true; public static string ReadLine() { if(IsDebug) { if(sr == null) { sr = new System.IO.StringReader(InitText.Trim()); } return sr.ReadLine(); } else { return Console.ReadLine(); } } public static int[] GetInt(char delimiter = ' ') { string[] inpt = ReadLine().Split(delimiter); int[] ret = new int[inpt.Length]; for(int i=0; i