結果
問題 | No.403 2^2^2 |
ユーザー |
![]() |
提出日時 | 2016-08-07 15:12:38 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,089 bytes |
コンパイル時間 | 1,737 ms |
コンパイル使用メモリ | 167,808 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-07 07:19:14 |
合計ジャッジ時間 | 2,897 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
#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 ) );x %= m;if( x == 0 ) return 0;if( n == 0 ) return 1;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) ^ Cvoid 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;}