結果
| 問題 |
No.276 連続する整数の和(1)
|
| コンテスト | |
| ユーザー |
明智重蔵
|
| 提出日時 | 2015-09-19 05:45:33 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 22 ms / 1,000 ms |
| コード長 | 1,561 bytes |
| コンパイル時間 | 1,644 ms |
| コンパイル使用メモリ | 103,808 KB |
| 実行使用メモリ | 17,920 KB |
| 最終ジャッジ日時 | 2024-07-19 07:52:02 |
| 合計ジャッジ時間 | 2,373 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 10 |
コンパイルメッセージ
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;
class Program
{
static string InputPattern = "Input3";
static List<string> GetInputList()
{
var WillReturn = new List<string>();
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<string> InputList = GetInputList();
long N = long.Parse(InputList[0]);
//Aから連続する3つの数の和は、
//A+A+1+A+2 = 3A+3 = 3*(A+1)
//Aの係数と、定数の、最大公約数をユークリッドの互助法で求める
long Keisuu = N;
//等差数列の和の公式で1からN-1までの和を求める
long Makkou = N - 1;
long Teisuu = Makkou * (Makkou + 1) / 2;
Console.WriteLine(DeriveGCD(Keisuu, Teisuu));
}
//ユークリッドの互除法で2数の最大公約数を求める
static long DeriveGCD(long pVal1, long pVal2)
{
long WarareruKazu = pVal2;
long WaruKazu = pVal1;
while (true) {
long Amari = WarareruKazu % WaruKazu;
if (Amari == 0) return WaruKazu;
WarareruKazu = WaruKazu;
WaruKazu = Amari;
}
}
}
明智重蔵