AtCoderのARC
次のARCの問題へ
前のARCの問題へ
ARC107-A Simple Math
C#のソース
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("1 2 3");
//18
}
else if (InputPattern == "Input2") {
WillReturn.Add("1000000000 987654321 123456789");
//951633476
}
else {
string wkStr;
while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
}
return WillReturn;
}
const long Hou = 998244353;
static void Main()
{
List<string> InputList = GetInputList();
long[] wkArr = InputList[0].Split(' ').Select(pX => long.Parse(pX)).ToArray();
long A = wkArr[0];
long B = wkArr[1];
long C = wkArr[2];
Func<long, long> DeriveSumFunc = pLimitVal =>
{
return pLimitVal * (pLimitVal + 1) / 2;
};
long SumA = DeriveSumFunc(A) % Hou;
long SumB = DeriveSumFunc(B) % Hou;
long SumC = DeriveSumFunc(C) % Hou;
long Answer = SumA;
Answer *= SumB;
Answer %= Hou;
Answer *= SumC;
Answer %= Hou;
Console.WriteLine(Answer);
}
}
解説
因数分解すると
等差数列Aの総和 * 等差数列Bの総和 * 等差数列Cの総和
になるので、この値を計算してます。