結果
| 問題 |
No.276 連続する整数の和(1)
|
| コンテスト | |
| ユーザー |
明智重蔵
|
| 提出日時 | 2015-09-19 05:43:25 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,550 bytes |
| コンパイル時間 | 2,940 ms |
| コンパイル使用メモリ | 104,320 KB |
| 実行使用メモリ | 17,792 KB |
| 最終ジャッジ日時 | 2024-07-19 07:51:58 |
| 合計ジャッジ時間 | 2,426 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 3 WA * 7 |
コンパイルメッセージ
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();
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;
}
}
}
明智重蔵