using System; using System.Collections.Generic; class Program { static string InputPattern = "Input3"; static List GetInputList() { var WillReturn = new List(); if (InputPattern == "Input1") { WillReturn.Add("3"); //3 } else if (InputPattern == "Input2") { WillReturn.Add("2"); //1 } else { string wkStr; while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr); } return WillReturn; } //No.276 連続する整数の和(1) static void Main() { List InputList = GetInputList(); int N = int.Parse(InputList[0]); //Aから連続する3つの数の和は、 //A+A+1+A+2 = 3A+3 = 3*(A+1) //Aの係数と、定数の、最大公約数をユークリッドの互助法で求める int Keisuu = N; //等差数列の和の公式で1からN-1までの和を求める int Makkou = N - 1; int Teisuu = Makkou * (Makkou + 1) / 2; Console.WriteLine(DeriveGCD(Keisuu, Teisuu)); } //ユークリッドの互除法で2数の最大公約数を求める static int DeriveGCD(int pVal1, int pVal2) { int WarareruKazu = pVal2; int WaruKazu = pVal1; while (true) { int Amari = WarareruKazu % WaruKazu; if (Amari == 0) return WaruKazu; WarareruKazu = WaruKazu; WaruKazu = Amari; } } }