結果

問題 No.403 2^2^2
ユーザー AreTrashAreTrash
提出日時 2019-01-24 16:26:55
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 5,389 bytes
コンパイル時間 955 ms
コンパイル使用メモリ 110,720 KB
実行使用メモリ 19,200 KB
最終ジャッジ日時 2024-09-16 04:38:20
合計ジャッジ時間 2,903 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
18,944 KB
testcase_01 AC 27 ms
18,816 KB
testcase_02 AC 28 ms
19,200 KB
testcase_03 AC 27 ms
19,072 KB
testcase_04 AC 28 ms
18,944 KB
testcase_05 AC 28 ms
18,944 KB
testcase_06 AC 28 ms
19,072 KB
testcase_07 AC 28 ms
18,944 KB
testcase_08 AC 28 ms
18,816 KB
testcase_09 AC 27 ms
18,944 KB
testcase_10 AC 28 ms
18,816 KB
testcase_11 AC 28 ms
18,944 KB
testcase_12 AC 27 ms
19,200 KB
testcase_13 AC 28 ms
18,944 KB
testcase_14 AC 28 ms
19,072 KB
testcase_15 AC 27 ms
19,072 KB
testcase_16 AC 28 ms
18,944 KB
testcase_17 AC 28 ms
19,200 KB
testcase_18 AC 26 ms
18,944 KB
testcase_19 AC 27 ms
19,072 KB
testcase_20 AC 26 ms
18,816 KB
testcase_21 AC 26 ms
19,072 KB
testcase_22 AC 26 ms
18,944 KB
testcase_23 AC 26 ms
18,816 KB
testcase_24 AC 26 ms
19,200 KB
testcase_25 AC 25 ms
19,072 KB
testcase_26 AC 25 ms
18,944 KB
testcase_27 AC 26 ms
18,944 KB
testcase_28 AC 27 ms
19,072 KB
testcase_29 AC 27 ms
18,816 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.IO;
using System.Collections.Generic;
using System.Linq;

namespace No403
{
    public class Program
    {
        void Solve(StreamScanner ss, StreamWriter sw)
        {
            //---------------------------------
            var S = ss.Next(String).Split('^').Select(long.Parse).ToArray();
            var A = (ModInt)S[0];
            var B = S[1];
            var C = S[2];

            if (A.Value == 0)
            {
                sw.WriteLine($"{0} {0}");
                return;
            }

            var ans1 = A.Pow(B).Pow(C);
            var ans2 = A.Pow(new ModInt(B, 1000000006).Pow(C).Value);
            sw.WriteLine($"{ans1} {ans2}");
            //---------------------------------
        }

        static void Main()
        {
            var ss = new StreamScanner(new StreamReader(Console.OpenStandardInput()));
            var sw = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
            new Program().Solve(ss, sw);
            sw.Flush();
        }

        static readonly Func<string, string> String = s => s;
    }

    public struct ModInt
    {
        public static int DefaultMod = 1000000007;

        readonly long value;
        readonly int mod;

        public int Value { get { return (int)value; } }
        public int Mod { get { return mod; } }
        public ModInt Inverse { get { return GetInverse(); } }

        public ModInt(long value) : this(value, DefaultMod) { }

        public ModInt(long value, int mod)
        {
            value %= mod;
            this.value = value < 0 ? value + mod : value;
            this.mod = mod;
        }

        ModInt GetInverse()
        {
            if (value == 0) throw new InvalidOperationException("value must NOT equal 0");
            return Pow(Mod - 2);
        }

        public ModInt Square()
        {
            return this * this;
        }

        public ModInt Pow(long exp)
        {
            if (exp == 0) return new ModInt(1, mod);
            if (exp % 2 == 0) return Pow(exp / 2).Square();
            return this * Pow(exp - 1);
        }

        public static ModInt Parse(string str)
        {
            return long.Parse(str);
        }

        public static ModInt Parse(string str, int mod)
        {
            return new ModInt(long.Parse(str), mod);
        }

        public static implicit operator ModInt(long value)
        {
            return new ModInt(value);
        }

        static void AssertSameMod(ModInt left, ModInt right)
        {
            if (left.mod != right.mod) throw new ArgumentException($"{nameof(left.Mod)} != {nameof(right.Mod)}");
        }

        public static ModInt operator +(ModInt left, ModInt right)
        {
            AssertSameMod(left, right);
            return new ModInt(left.value + right.value, left.mod);
        }

        public static ModInt operator +(ModInt mi, long num)
        {
            return mi + new ModInt(num, mi.mod);
        }

        public static ModInt operator -(ModInt left, ModInt right)
        {
            AssertSameMod(left, right);
            return new ModInt(left.value - right.value, left.mod);
        }

        public static ModInt operator -(ModInt mi, long num)
        {
            return mi - new ModInt(num, mi.mod);
        }

        public static ModInt operator *(ModInt left, ModInt right)
        {
            AssertSameMod(left, right);
            return new ModInt(left.value * right.value, left.mod);
        }

        public static ModInt operator *(ModInt mi, long num)
        {
            return mi * new ModInt(num, mi.mod);
        }

        public static ModInt operator /(ModInt left, ModInt right)
        {
            return left * right.Inverse;
        }

        public static ModInt operator /(ModInt mi, long num)
        {
            return mi / new ModInt(num, mi.mod);
        }

        public override bool Equals(object obj)
        {
            if (!(obj is ModInt)) return false;
            var mi = (ModInt)obj;
            return value == mi.value && mod == mi.mod;
        }

        public override int GetHashCode()
        {
            return value.GetHashCode();
        }

        public override string ToString()
        {
            return value.ToString();
        }
    }

    public class StreamScanner
    {
        static readonly char[] Sep = {' '};
        readonly Queue<string> buffer = new Queue<string>();
        readonly TextReader textReader;

        public StreamScanner(TextReader textReader)
        {
            this.textReader = textReader;
        }

        public T Next<T>(Func<string, T> parser)
        {
            if (buffer.Count != 0) return parser(buffer.Dequeue());
            var nextStrings = textReader.ReadLine().Split(Sep, StringSplitOptions.RemoveEmptyEntries);
            foreach (var nextString in nextStrings) buffer.Enqueue(nextString);
            return Next(parser);
        }

        public T[] Next<T>(Func<string, T> parser, int x)
        {
            var ret = new T[x];
            for (var i = 0; i < x; ++i) ret[i] = Next(parser);
            return ret;
        }

        public T[][] Next<T>(Func<string, T> parser, int x, int y)
        {
            var ret = new T[y][];
            for (var i = 0; i < y; ++i) ret[i] = Next(parser, x);
            return ret;
        }
    }
}
0