結果

問題 No.403 2^2^2
ユーザー tentententen
提出日時 2021-01-25 15:55:01
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,161 bytes
コンパイル時間 3,027 ms
コンパイル使用メモリ 81,496 KB
実行使用メモリ 57,116 KB
最終ジャッジ日時 2023-09-04 07:41:15
合計ジャッジ時間 9,534 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 157 ms
56,724 KB
testcase_01 AC 155 ms
56,836 KB
testcase_02 AC 154 ms
56,584 KB
testcase_03 AC 156 ms
56,976 KB
testcase_04 AC 154 ms
56,872 KB
testcase_05 AC 154 ms
56,444 KB
testcase_06 AC 155 ms
56,892 KB
testcase_07 AC 154 ms
56,716 KB
testcase_08 AC 154 ms
56,684 KB
testcase_09 AC 155 ms
57,024 KB
testcase_10 AC 155 ms
56,864 KB
testcase_11 AC 154 ms
56,752 KB
testcase_12 AC 154 ms
56,716 KB
testcase_13 AC 154 ms
56,912 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 155 ms
57,052 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 156 ms
56,968 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 154 ms
56,728 KB
testcase_23 AC 155 ms
56,984 KB
testcase_24 WA -
testcase_25 AC 154 ms
57,116 KB
testcase_26 AC 152 ms
56,716 KB
testcase_27 AC 155 ms
56,856 KB
testcase_28 WA -
testcase_29 AC 156 ms
56,728 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static final int MOD = 1000000007;
    static final int MODN = MOD - 1;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        int idx = line.indexOf('^');
        long a = Long.parseLong(line.substring(0, idx)) % MOD;
        int next = line.indexOf('^', idx + 1);
        long b = Long.parseLong(line.substring(idx + 1, next));
        long c = Long.parseLong(line.substring(next + 1, line.length()));
        long x = pow(pow(a, b), c);
        long y = pow(a, powmod(b % MOD, c));
        System.out.println(x + " " + y);
    }
    
    static long pow(long x, long p) {
        if (p == 0) {
            return 1;
        } else if (p % 2 == 0) {
            return pow(x * x % MOD, p / 2);
        } else {
            return pow(x, p - 1) * x % MOD;
        }
    }
    
    static long powmod(long x, long p) {
        if (p == 0) {
            return 1;
        } else if (p % 2 == 0) {
            return powmod(x * x % MODN, p / 2);
        } else {
            return powmod(x, p - 1) * x % MODN;
        }
    }
    
    
}
0