結果
問題 | No.403 2^2^2 |
ユーザー |
![]() |
提出日時 | 2023-10-21 04:34:46 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 985 bytes |
コンパイル時間 | 1,118 ms |
コンパイル使用メモリ | 123,616 KB |
最終ジャッジ日時 | 2025-02-17 12:17:45 |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
#include<iostream>#include<vector>#include<algorithm>#include<cstring>#include<cassert>#include<cmath>#include<ctime>#include<iomanip>#include<numeric>#include<stack>#include<queue>#include<map>#include<unordered_map>#include<set>#include<unordered_set>#include<bitset>#include<random>using namespace std;const int mod = (int)1e9+7;string S;long long f(long long P,long long N,int M){long long res = 1;P %= M;while(N){if(N & 1) res = res*P%M;P = P*P%M;N >>= 1;}return res;}void solve(){cin >> S;int l = -1,r = -1;for(int i = 0;i < (int)S.size();i++) if(S[i] == '^'){if(l < 0) l = i;else r = i;}long long A = stoll(S.substr(0,l)),B = stoll(S.substr(l+1,r-l-1)),C = stoll(S.substr(r+1));long long L = f(f(A,B,mod),C,mod);long long R = A%mod == 0 ? 0:f(A,f(B,C,mod-1),mod);cout << L << " " << R << endl;}int main(){ios::sync_with_stdio(false);cin.tie(nullptr);int tt = 1;//cin >> tt;while(tt--) solve();}