結果
| 問題 |
No.403 2^2^2
|
| ユーザー |
tossy
|
| 提出日時 | 2016-07-22 23:24:41 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,262 bytes |
| コンパイル時間 | 784 ms |
| コンパイル使用メモリ | 90,624 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-11-06 09:23:14 |
| 合計ジャッジ時間 | 1,687 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 3 |
| other | WA * 27 |
ソースコード
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define INF 1<<30
#define MOD 1000000007
// x^n mod MOD
long mod_pow(long x, long n, long m){
long res=1;
while(n>0){
if(n&1) res = res*x%m;
x=(x*x)%m;
n>>=1;
}
return res;
}
int main(){
long a,b,c;
string s;
cin>>s;
int idx=s.find('^');
a = atoi(s.substr(0, idx).c_str());
int i2 =s.find('^', idx+1);
b = atoi(s.substr(idx+1, i2-idx).c_str());
int i3 =s.find('^', i2+1);
c = atoi(s.substr(i2+1, i3-i2).c_str());
dbg(a); dbg(b); dbg(c);
long r1 = mod_pow(mod_pow(a, b, MOD), c, MOD);
long r2;
if(a%MOD==0){
r2=0;
} else{
// use a^(p-1) = 1 (mod p)
long pw = mod_pow(b, c, MOD-1);
r2 = mod_pow(a, pw, MOD);
}
cout<<r1<<" "<<r2<<endl;
return 0;
}
tossy