結果
| 問題 |
No.403 2^2^2
|
| ユーザー |
uafr_cs
|
| 提出日時 | 2016-07-22 23:52:34 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,902 bytes |
| コンパイル時間 | 2,974 ms |
| コンパイル使用メモリ | 82,656 KB |
| 実行使用メモリ | 55,240 KB |
| 最終ジャッジ日時 | 2024-11-06 09:32:20 |
| 合計ジャッジ時間 | 8,909 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 23 WA * 4 |
ソースコード
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(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);
}
}
uafr_cs