結果

問題 No.403 2^2^2
ユーザー uafr_cs
提出日時 2016-07-22 23:57:43
言語 Java8
(openjdk 1.8.0.222)
結果
AC  
実行時間 133 ms
コード長 1,972 Byte
コンパイル時間 2,006 ms
使用メモリ 22,096 KB
最終ジャッジ日時 2019-11-26 11:56:22

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
0_sample_01.in AC 119 ms
21,584 KB
0_sample_02.in AC 118 ms
21,620 KB
0_sample_03.in AC 119 ms
21,640 KB
1_small_01.in AC 123 ms
21,608 KB
1_small_02.in AC 119 ms
21,612 KB
1_small_03.in AC 123 ms
21,620 KB
1_small_04.in AC 119 ms
21,660 KB
1_small_05.in AC 124 ms
21,888 KB
1_small_06.in AC 120 ms
21,652 KB
1_small_07.in AC 122 ms
21,648 KB
2_large_01.in AC 122 ms
21,660 KB
2_large_02.in AC 121 ms
21,684 KB
2_large_03.in AC 119 ms
21,668 KB
2_large_04.in AC 119 ms
21,612 KB
2_large_05.in AC 121 ms
21,720 KB
2_large_06.in AC 123 ms
21,616 KB
2_large_07.in AC 117 ms
21,612 KB
2_large_08.in AC 121 ms
21,728 KB
2_large_09.in AC 124 ms
22,056 KB
2_large_10.in AC 120 ms
21,696 KB
2_large_11.in AC 128 ms
22,064 KB
2_large_12.in AC 133 ms
22,096 KB
2_large_13.in AC 117 ms
21,660 KB
2_large_14.in AC 125 ms
21,684 KB
2_large_15.in AC 131 ms
22,064 KB
2_large_16.in AC 121 ms
21,620 KB
2_large_17.in AC 121 ms
21,756 KB
2_large_18.in AC 125 ms
21,900 KB
2_large_19.in AC 127 ms
21,988 KB
challenge01.txt AC 123 ms
21,656 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