using System; using System.Collections.Generic; using System.Linq; //No395 永遠の17歳 class Program { static string InputPattern = "InputX"; static List GetInputList() { var WillReturn = new List(); if (InputPattern == "Input1") { WillReturn.Add("51"); //44 } else if (InputPattern == "Input2") { WillReturn.Add("3"); //-1 } else if (InputPattern == "Input3") { WillReturn.Add("15"); //8 } else { string wkStr; while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr); } return WillReturn; } static void Main() { List InputList = GetInputList(); int A = int.Parse(InputList[0]); int AnswerX = -1; bool HasAnswer = false; for (int X = 2; X < int.MaxValue; X++) { List NumList = DeriveNumList(X, A); //桁数は進数に対して、単調減少なので、 //2桁未満になったら、17にはならない if (NumList.Count < 2) break; if (NumList.Count > 2) continue; int Keta2 = NumList[0]; int Keta1 = NumList[1]; if (Keta2 != 1) continue; if (Keta1 != 7) continue; HasAnswer = true; AnswerX = X; } if (HasAnswer) Console.WriteLine(AnswerX); else Console.WriteLine(-1); } //N進数での数字の並びを返す static List DeriveNumList(int pShinsuu, int pVal) { var WillReturn = new List(); do { int ModVal = pVal % pShinsuu; WillReturn.Add(ModVal); pVal /= pShinsuu; } while (pVal > 0); WillReturn.Reverse(); return WillReturn; } }