using System; using System.Collections.Generic; using System.Linq; class Program { static string InputPattern = "Input2"; static List GetInputList() { var WillReturn = new List(); if (InputPattern == "Input1") { WillReturn.Add("2"); WillReturn.Add("2 10"); WillReturn.Add("9 9"); //1 0 3 //3 8 8 //9の9乗は387420489です。これは9桁の数(10の8乗オーダー)であり、 //最上位の数は3、上から2番目の数は8です。 //上から3番目の数は7ですが、切り捨てます。 } else { string wkStr; while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr); } return WillReturn; } struct ABInfoDef { internal int A; internal int B; } static void Main() { List InputList = GetInputList(); var ABInfoList = new List(); foreach (string EachStr in InputList.Skip(1)) { int[] wkArr = EachStr.Split(' ').Select(X => int.Parse(X)).ToArray(); ABInfoList.Add(new ABInfoDef() { A = wkArr[0], B = wkArr[1] }); } ABInfoList.ForEach(Solve); } struct ResultInfoDef { internal double X; internal double Y; internal double Z; } static void Solve(ABInfoDef pABInfo) { double Sahen = pABInfo.B * Math.Log10(pABInfo.A); //丸め誤差が一番小さい値を解とする var ResultInfoList = new List(); for (double X = 1; X <= 9; X++) { for (double Y = 0; Y <= 9; Y++) { double Z = Sahen - Math.Log10(X + Y / 10); ResultInfoList.Add(new ResultInfoDef() { X = X, Y = Y, Z = Z }); } } ResultInfoDef Answer = ResultInfoList.OrderBy(A => Math.Abs(A.Z - Math.Truncate(A.Z))).First(); Console.WriteLine("{0} {1} {2}", Answer.X, Answer.Y, Math.Round(Answer.Z)); } }