結果

問題 No.16 累乗の加算
ユーザー 明智重蔵明智重蔵
提出日時 2015-08-15 15:03:34
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,893 bytes
コンパイル時間 2,270 ms
コンパイル使用メモリ 106,112 KB
実行使用メモリ 24,000 KB
最終ジャッジ日時 2023-09-25 12:04:13
合計ジャッジ時間 4,024 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
21,824 KB
testcase_01 AC 63 ms
21,904 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 63 ms
21,928 KB
testcase_12 WA -
testcase_13 AC 63 ms
21,912 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;
using System.Linq;

class Program
{
    static string InputPattern = "Input3";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("2 3");
            WillReturn.Add("1 2 3");
            //14
            //x + xの2乗 + xの3乗 ,x=2 を表しております。なのでこの計算値はこのようになります。
            //x + xの2乗 + xの3乗 = 2 + 4 + 8 = 14
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("2 2");
            WillReturn.Add("0 100");
            //253110
            //xの0乗 + xの100乗 = 1 + 1267650600228229401496703205376
            //となるが、1000003で割った余りは、253110となる。
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        int X = InputList[0].Split(' ').Select(A => int.Parse(A)).First();
        int[] AArr = InputList[1].Split(' ').Select(A => int.Parse(A)).ToArray();

        Console.WriteLine(AArr.Sum(A => DeriveBekijyou(X, A) % 1000003));
    }

    //繰り返し2乗法で、XのN乗を求める
    static long DeriveBekijyou(int pX, int pN)
    {
        long CurrJyousuu = pX % 1000003;
        long CurrShisuu = 1;
        long WillReturn = 1;

        while (true) {
            //そのビットが立っていた場合
            if ((pN & CurrShisuu) > 0) {
                WillReturn = (WillReturn * CurrJyousuu) % 1000003;
            }

            CurrShisuu *= 2;
            if (CurrShisuu > pN) return WillReturn;
            CurrJyousuu = (CurrJyousuu * CurrJyousuu) % 1000003;
        }
    }
}
0