結果
問題 |
No.403 2^2^2
|
ユーザー |
![]() |
提出日時 | 2016-08-07 15:11:02 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,108 bytes |
コンパイル時間 | 1,450 ms |
コンパイル使用メモリ | 166,692 KB |
実行使用メモリ | 13,640 KB |
最終ジャッジ日時 | 2024-11-07 07:18:53 |
合計ジャッジ時間 | 5,196 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 15 WA * 3 TLE * 1 -- * 8 |
ソースコード
#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; }