結果

問題 No.403 2^2^2
ユーザー uafr_csuafr_cs
提出日時 2016-07-22 23:57:43
言語 Java19
(openjdk 21)
結果
AC  
実行時間 164 ms / 2,000 ms
コード長 1,972 bytes
コンパイル時間 2,322 ms
コンパイル使用メモリ 76,332 KB
実行使用メモリ 57,208 KB
最終ジャッジ日時 2023-08-06 12:11:18
合計ジャッジ時間 8,608 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 151 ms
57,096 KB
testcase_01 AC 151 ms
56,724 KB
testcase_02 AC 149 ms
56,800 KB
testcase_03 AC 149 ms
56,880 KB
testcase_04 AC 157 ms
56,812 KB
testcase_05 AC 159 ms
57,172 KB
testcase_06 AC 151 ms
56,928 KB
testcase_07 AC 150 ms
56,776 KB
testcase_08 AC 154 ms
56,932 KB
testcase_09 AC 153 ms
56,836 KB
testcase_10 AC 154 ms
56,804 KB
testcase_11 AC 157 ms
57,028 KB
testcase_12 AC 155 ms
56,956 KB
testcase_13 AC 153 ms
56,876 KB
testcase_14 AC 164 ms
57,208 KB
testcase_15 AC 150 ms
55,228 KB
testcase_16 AC 149 ms
56,920 KB
testcase_17 AC 153 ms
57,092 KB
testcase_18 AC 154 ms
57,168 KB
testcase_19 AC 153 ms
57,016 KB
testcase_20 AC 154 ms
56,928 KB
testcase_21 AC 154 ms
56,636 KB
testcase_22 AC 154 ms
57,156 KB
testcase_23 AC 156 ms
56,972 KB
testcase_24 AC 156 ms
56,880 KB
testcase_25 AC 152 ms
56,880 KB
testcase_26 AC 156 ms
56,800 KB
testcase_27 AC 153 ms
56,780 KB
testcase_28 AC 156 ms
57,176 KB
testcase_29 AC 152 ms
56,652 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.math.BigInteger;
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Set;

public class Main {
	
	public static final long MOD = 1000000007L;
	
	public static long mod_pow(long a, long p, long MOD){
		if(p == 0){
			return 1;
		}else if(p == 1){
			return a % MOD;
		}else if(p % 2 != 0){
			return ((a % MOD) * mod_pow(a, p - 1, MOD)) % MOD;
		}else{
			final long ret = mod_pow(a, p / 2, MOD);
			
			return (ret * ret) % MOD;
		}
	}
	
	public static final BigInteger TWO = BigInteger.valueOf(2); 
	public static BigInteger mod_pow(BigInteger a, BigInteger p, BigInteger MOD){
		if(a.mod(MOD) == BigInteger.ZERO){
			return BigInteger.ZERO;
		}else if(p.equals(BigInteger.ZERO)){
			return BigInteger.ONE;
		}else if(p.equals(BigInteger.ONE)){
			return a.mod(MOD);
		}else if(p.mod(TWO).equals(BigInteger.ONE)){
			return (a.mod(MOD)).multiply(mod_pow(a, p.subtract(BigInteger.ONE), MOD)).mod(MOD);
		}else{
			final BigInteger ret = mod_pow(a, p.divide(TWO), MOD);
			
			return ret.multiply(ret).mod(MOD);
		}
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		final String[] inputs = sc.next().split("[^0-9]");
		
		
		final long A = Long.parseLong(inputs[0]);
		final long B = Long.parseLong(inputs[1]);
		final long C = Long.parseLong(inputs[2]);
		//System.out.println("out");
		
		//final long fst = mod_pow(mod_pow(A, B, MOD), C, MOD);
		//final long snd = mod_pow(A, mod_pow(B, C, MOD - 1), MOD);
		final BigInteger big_A = BigInteger.valueOf(A);
		final BigInteger big_B = BigInteger.valueOf(B);
		final BigInteger big_C = BigInteger.valueOf(C);
		final BigInteger big_MOD = BigInteger.valueOf(MOD);
		
		final BigInteger fst = mod_pow(mod_pow(big_A, big_B, big_MOD), big_C, big_MOD);
		final BigInteger snd = mod_pow(big_A, mod_pow(big_B, big_C, big_MOD.subtract(BigInteger.ONE)), big_MOD);
		System.out.println(fst + " " + snd);
		
	}

}
0