using System; using System.Collections.Generic; using System.Linq; //YukiCoder339 何人が回答したのか //https://yukicoder.me/problems/no/339 class Program { static string InputPattern = "InputX"; static List GetInputList() { var WillReturn = new List(); if (InputPattern == "Input1") { WillReturn.Add("2"); WillReturn.Add("50"); WillReturn.Add("50"); //2 } else if (InputPattern == "Input2") { WillReturn.Add("1"); WillReturn.Add("100"); //1 } else if (InputPattern == "Input3") { WillReturn.Add("3"); WillReturn.Add("60"); WillReturn.Add("30"); WillReturn.Add("10"); //10 } else { string wkStr; while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr); } return WillReturn; } static void Main() { List InputList = GetInputList(); int[] AArr = InputList.Skip(1).Select(X => int.Parse(X)).ToArray(); int CurrGCD = AArr[0]; foreach (int EachA in AArr.Skip(1)) { CurrGCD = DeriveGCD(EachA, CurrGCD); } Console.WriteLine(AArr.Sum(X => X / CurrGCD)); } //ユークリッドの互除法で2数の最大公約数を求める static private int DeriveGCD(int pVal1, int pVal2) { pVal1 = Math.Abs(pVal1); pVal2 = Math.Abs(pVal2); int WarareruKazu = Math.Max(pVal1, pVal2); int WaruKazu = Math.Min(pVal1, pVal2); while (true) { int Amari = WarareruKazu % WaruKazu; if (Amari == 0) return WaruKazu; WarareruKazu = WaruKazu; WaruKazu = Amari; } } }