結果

問題 No.403 2^2^2
ユーザー alpha_virginisalpha_virginis
提出日時 2016-08-07 15:11:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,108 bytes
コンパイル時間 1,354 ms
コンパイル使用メモリ 162,564 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2024-04-24 22:07:42
合計ジャッジ時間 4,993 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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); }

long modpow(long x, long n, long m) {
  assert( not ( x == 0 and n == 0 ) );
  if( x % m == 0 ) return 0;
  if( n == 0 ) return 1;
  if( x == 0 ) return 0;
  long res = 1;
  long p = x;
  while( n != 0 ) {
    if( n & 0x01 ) res = (res * p) % m;
    p = (p * p) % m;
    n >>= 1;
  }
  return res;
}

constexpr long mod = 1000000007;

// (A ^ B) ^ C
void solve1(long a, long b, long c) {
  printf("%ld ", modpow(modpow(a, b, mod), c, mod));
}

// A ^ (B ^ C)
void solve2(long a, long b, long c) {
  printf("%ld\n", modpow(a, modpow(b, c, mod - 1), mod));
}


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