結果

問題 No.403 2^2^2
ユーザー 明智重蔵明智重蔵
提出日時 2021-11-23 17:31:09
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 62 ms / 2,000 ms
コード長 1,995 bytes
コンパイル時間 1,364 ms
コンパイル使用メモリ 66,100 KB
実行使用メモリ 15,912 KB
最終ジャッジ日時 2023-09-07 20:28:09
合計ジャッジ時間 4,935 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 59 ms
15,732 KB
testcase_01 AC 59 ms
15,788 KB
testcase_02 AC 58 ms
15,740 KB
testcase_03 AC 59 ms
15,732 KB
testcase_04 AC 59 ms
15,728 KB
testcase_05 AC 58 ms
15,812 KB
testcase_06 AC 58 ms
15,712 KB
testcase_07 AC 59 ms
15,672 KB
testcase_08 AC 61 ms
15,844 KB
testcase_09 AC 62 ms
15,852 KB
testcase_10 AC 61 ms
15,672 KB
testcase_11 AC 59 ms
15,768 KB
testcase_12 AC 59 ms
15,840 KB
testcase_13 AC 57 ms
15,812 KB
testcase_14 AC 59 ms
15,724 KB
testcase_15 AC 60 ms
15,716 KB
testcase_16 AC 60 ms
15,808 KB
testcase_17 AC 58 ms
15,748 KB
testcase_18 AC 59 ms
15,740 KB
testcase_19 AC 59 ms
15,848 KB
testcase_20 AC 60 ms
15,756 KB
testcase_21 AC 61 ms
15,828 KB
testcase_22 AC 60 ms
15,808 KB
testcase_23 AC 58 ms
15,704 KB
testcase_24 AC 58 ms
15,912 KB
testcase_25 AC 59 ms
15,736 KB
testcase_26 AC 59 ms
15,780 KB
testcase_27 AC 61 ms
15,728 KB
testcase_28 AC 60 ms
15,808 KB
testcase_29 AC 58 ms
15,828 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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("2^2^2");
            //16 16
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("2^3^2");
            //64 512
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("10^10^10");
            //226732710 206165314
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    const long Hou = 1000000007;

    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];

        long Answer1 = 0;
        if (A % Hou > 0) {
            Answer1 = DeriveBekijyou(A, B, Hou);
            Answer1 = DeriveBekijyou(Answer1, C, Hou);
        }

        long Answer2 = 0;
        if (A % Hou > 0) {
            long ModPow = DeriveBekijyou(B, C, Hou - 1);
            Answer2 = DeriveBekijyou(A, ModPow, Hou);
        }

        Console.WriteLine("{0} {1}", Answer1, Answer2);
    }

    // 繰り返し2乗法で、(NのP乗) Mod Mを求める
    static long DeriveBekijyou(long pN, long pP, long pM)
    {
        long CurrJyousuu = pN % pM;
        long CurrShisuu = 1;
        long WillReturn = 1;

        while (true) {
            // 対象ビットが立っている場合
            if ((pP & CurrShisuu) > 0) {
                WillReturn = (WillReturn * CurrJyousuu) % pM;
            }

            CurrShisuu *= 2;
            if (CurrShisuu > pP) return WillReturn;
            CurrJyousuu = (CurrJyousuu * CurrJyousuu) % pM;
        }
    }
}
0