結果
問題 |
No.339 何人が回答したのか
|
ユーザー |
![]() |
提出日時 | 2024-10-13 07:50:18 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 32 ms / 1,000 ms |
コード長 | 1,902 bytes |
コンパイル時間 | 848 ms |
コンパイル使用メモリ | 108,928 KB |
実行使用メモリ | 19,200 KB |
最終ジャッジ日時 | 2024-10-13 07:50:24 |
合計ジャッジ時間 | 4,263 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 61 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System; using System.Collections.Generic; using System.Linq; class Program { static string InputPattern = "InputX"; static List<string> GetInputList() { var WillReturn = new List<string>(); if (InputPattern == "Input1") { WillReturn.Add("2"); WillReturn.Add("50"); WillReturn.Add("50"); //2 //1人が選択肢1を、1人が選択肢2を選んだと考えられる } else if (InputPattern == "Input2") { WillReturn.Add("1"); WillReturn.Add("100"); //1 //1人が選択肢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<string> 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; } } }