結果

問題 No.403 2^2^2
ユーザー alpha_virginisalpha_virginis
提出日時 2016-08-07 14:46:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,748 bytes
コンパイル時間 1,797 ms
コンパイル使用メモリ 163,492 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 22:07:27
合計ジャッジ時間 2,780 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 2 ms
5,376 KB
testcase_18 WA -
testcase_19 AC 2 ms
5,376 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 1 ms
5,376 KB
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

template<typename T> T in() { abort(); return T(); }
template<> std::string in() { std::string str; std::cin >> str; return str; }
template<> int in() { int x; scanf("%d", &x); return x; }

template<typename T> void out(T x) { abort(); }
template<> void out(std::string x) { std::cout << x << std::endl; }
template<> void out(int x) { printf("%d\n", x); }

template<typename T>
T pow(T x, long n) {
  T res = 1;
  T p = x;
  while( n != 0 ) {
    if( n & 0x01 ) res *= p;
    p *= p;
    n >>= 1;
  }
  return res;
}

template<long P = 1000000007>
class Mod {
public:
  Mod() : a(0) {}
  Mod(long x) : a(x % P) {}
  long get() { return a; }
  Mod operator + (Mod x) { return Mod<P>((a + x.get()) % P); }
  Mod operator += (Mod x) { a = (a + x.get()) % P; return *this; }
  Mod operator - (Mod x) { return Mod<P>((a + P - x.get()) % P); }
  Mod operator -= (Mod x) { a = (a + P - x.a) % P; return *this; }
  Mod operator * (Mod x) { return Mod<P>((a * x.get()) % P); }
  Mod operator *= (Mod x) { a = (a * x.a) % P; return *this; }
  Mod operator / (Mod x) { return *this * pow(x, P - 2); }
  Mod operator /= (Mod x) { a = (*this * pow(x, P - 2)); return *this; }
private:
  long a;
};


// (A ^ B) ^ C
void solve1(long a, long b, long c) {
  b %= 1000000007 - 1;
  c %= 1000000007 - 1;
  Mod<> res = a;
  res = pow(pow(Mod<>(a), b), c);
  printf("%ld ", res.get());
}

// A ^ (B ^ C)
void solve2(long a, long b, long c) {
  c %= 1000000007 - 1;
  auto t = pow(Mod<1000000006>(b), c);
  Mod<> res = pow(Mod<>(a), t.get());
  printf("%ld\n", res.get());
}


int main() {
  char buf[256];
  scanf("%s", buf);
  long a, b, c;
  sscanf(buf, "%ld^%ld^%ld", &a, &b, &c);
  solve1(a, b, c);
  solve2(a, b, c);
  
  
  return 0;
}
0