結果

問題 No.276 連続する整数の和(1)
ユーザー 明智重蔵明智重蔵
提出日時 2015-09-19 05:43:25
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,550 bytes
コンパイル時間 3,980 ms
コンパイル使用メモリ 103,304 KB
実行使用メモリ 22,708 KB
最終ジャッジ日時 2023-09-26 13:31:26
合計ジャッジ時間 4,945 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
20,644 KB
testcase_01 AC 55 ms
22,708 KB
testcase_02 AC 54 ms
22,616 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

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;
        }
    }
}
0