結果

問題 No.403 2^2^2
ユーザー mayoko_mayoko_
提出日時 2016-07-22 23:11:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,843 bytes
コンパイル時間 963 ms
コンパイル使用メモリ 101,804 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-24 02:36:25
合計ジャッジ時間 1,604 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>
#include<stack>
#include<random>

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, -1, 0, 1};
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

ll mod_pow(ll x, ll p, ll MOD) {
    ll a = 1;
    while (p) {
        if (p%2) a = a*x%MOD;
        x = x*x%MOD;
        p/=2;
    }
    return a;
}

// mod_inverse
ll mod_inverse(ll a, ll m) {
    return mod_pow(a, m-2, m);
}

pair<pair<ll, ll>, ll> unko(string s) {
    int n = s.size();
    pair<pair<ll, ll>, ll> ret;
    int div = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == '^') {
            if (ret.first.first == 0) {
                ret.first.first = stoll(s.substr(0, i));
                div = i+1;
            } else {
                ret.first.second = stoll(s.substr(div, i-div));
                ret.second = stoll(s.substr(i+1));
            }
        }
    }
    return ret;
}

const ll MOD = 1e9+7;

ll solve1(ll A, ll B, ll C) {
    ll tmp = mod_pow(A%MOD, B, MOD);
    return mod_pow(tmp, C, MOD);
}

ll solve2(ll A, ll B, ll C) {
    ll tmp = mod_pow(B%(MOD-1), C, MOD-1);
    return mod_pow(A%MOD, tmp, MOD);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll A, B, C;
    {
        string s;
        cin >> s;
        auto p = unko(s);
        A = p.first.first, B = p.first.second, C = p.second;
    }
    cout << solve1(A, B, C) << " " << solve2(A, B, C) << endl;
    return 0;
}
0