結果
| 問題 |
No.403 2^2^2
|
| コンテスト | |
| ユーザー |
明智重蔵
|
| 提出日時 | 2021-11-23 17:31:09 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 28 ms / 2,000 ms |
| コード長 | 1,995 bytes |
| コンパイル時間 | 4,630 ms |
| コンパイル使用メモリ | 107,136 KB |
| 実行使用メモリ | 19,328 KB |
| 最終ジャッジ日時 | 2024-06-25 14:12:29 |
| 合計ジャッジ時間 | 3,081 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 |
コンパイルメッセージ
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;
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;
}
}
}
明智重蔵